Determines if instance of Run method should suppress any exceptions.
Boolean value indicating if Run should suppress any exceptions. Default value is true.
Set this property to false to catch exceptions thrown by Run method.
In this example the transaction is opened before calling any WebDAV Engine methods. If any exception occurs in any interface implementation the transaction is rolled back.
public void ThreadProc()
{
string uriPrefix = ConfigurationManager.AppSettings["ListenerPrefix"];
HttpListener listener = new HttpListener();
listener.Prefixes.Add(uriPrefix);
string authType = ConfigurationManager.AppSettings["AuthenticationType"];
switch (authType)
{
case "Ntlm":
listener.AuthenticationSchemes = AuthenticationSchemes.Ntlm;
break;
case "Basic":
listener.AuthenticationSchemes = AuthenticationSchemes.Basic;
break;
case "None":
listener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
break;
}
listener.Start();
while (listening)
{
IAsyncResult result = listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);
result.AsyncWaitHandle.WaitOne();
}
}
public static void ListenerCallback(IAsyncResult result)
{
HttpListener listener = (HttpListener)result.AsyncState;
HttpListenerContext context = listener.EndGetContext(result);
WDEngine engine = new WDEngine(context.User);
engine.IgnoreException = false; // if any exception during Engine.Run call occurs exception will be thrown
if (UserAutorized(context, listener))
{
try
{
using (TransactionScope scope = new TransactionScope())
{
engine.Run(context, listener.Prefixes);
scope.Complete();
}
}
catch
{
// error during request processing occurred, transaction rolled back, continue listening
}
}
else
context.Response.StatusCode = 401;
if (response.StatusCode == 401)
ShowLoginDialog(context, response, listener);
try
{
context.Response.Close();
}
catch
{
// client closed connection before the content was sent
}
}
private static void ShowLoginDialog(HttpListenerContext context, WDResponse response, HttpListener listener)
{
switch (listener.AuthenticationSchemes)
{
case AuthenticationSchemes.Ntlm:
response.AddHeader("WWW-Authenticate", "NTLM");
byte[] message = new UTF8Encoding().GetBytes("Access denied");
context.Response.OutputStream.Write(message, 0, message.Length);
break;
case AuthenticationSchemes.Basic:
context.Response.AddHeader("WWW-Authenticate",
"Basic Realm=\"My WebDAV Server\"");
message = new UTF8Encoding().GetBytes("Access denied");
context.Response.ContentLength64 = message.Length;
context.Response.OutputStream.Write(message, 0, message.Length);
break;
}
}
Engine Class | ITHit.WebDAV.Server Namespace