From 04107c8cb6fd36080416ee4bb96ae332112a64b6 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 13 May 2020 20:01:04 +0200 Subject: [PATCH] WIP: find, and harden against User null issue --- .../WebDAVSharp.Server/WebDAVServer.cs | 22 +++++++++------- .../WebDAVSharp.Server/WebDavServer.cs | 26 +++++++++---------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/WebDavSharp/WebDAVSharp.Server/WebDAVServer.cs b/WebDavSharp/WebDAVSharp.Server/WebDAVServer.cs index ed1d74b..87085ba 100644 --- a/WebDavSharp/WebDAVSharp.Server/WebDAVServer.cs +++ b/WebDavSharp/WebDAVSharp.Server/WebDAVServer.cs @@ -36,17 +36,17 @@ namespace WebDAVSharp.Server /// /// Initializes a new instance of the class. /// - /// The + /// The /// store object that will provide - /// collections and documents for this + /// collections and documents for this /// . - /// The + /// The /// object that will handle the web server portion of - /// the WebDAV server; or + /// the WebDAV server; or /// null to use a fresh one. - /// A collection of HTTP method handlers to use by this + /// A collection of HTTP method handlers to use by this /// ; - /// or + /// or /// null to use the built-in method handlers. /// /// is null. @@ -91,8 +91,8 @@ namespace WebDAVSharp.Server } /// - /// Gets the - /// that this + /// Gets the + /// that this /// uses for /// the web server portion. /// @@ -138,7 +138,7 @@ namespace WebDAVSharp.Server } /// - /// Starts this + /// Starts this /// and returns once it has /// been started successfully. /// @@ -169,7 +169,7 @@ namespace WebDAVSharp.Server } /// - /// Starts this + /// Starts this /// and returns once it has /// been stopped successfully. /// @@ -241,6 +241,8 @@ namespace WebDAVSharp.Server IHttpListenerContext context = (IHttpListenerContext)state; + _log.Debug(" WebDAVSharp => " + context?.AdaptedInstance?.User?.Identity?.ToString()); + // For authentication Thread.SetData(Thread.GetNamedDataSlot(HttpUser), context.AdaptedInstance.User.Identity); diff --git a/WebDavSharp_MVC/WebDAVSharp.Server/WebDavServer.cs b/WebDavSharp_MVC/WebDAVSharp.Server/WebDavServer.cs index af03393..efde2a4 100644 --- a/WebDavSharp_MVC/WebDAVSharp.Server/WebDavServer.cs +++ b/WebDavSharp_MVC/WebDAVSharp.Server/WebDavServer.cs @@ -36,17 +36,17 @@ namespace WebDAVSharp.Server { /// /// Initializes a new instance of the class. /// - /// The + /// The /// store object that will provide - /// collections and documents for this + /// collections and documents for this /// . - /// The + /// The /// object that will handle the web server portion of - /// the WebDAV server; or + /// the WebDAV server; or /// null to use a fresh one. - /// A collection of HTTP method handlers to use by this + /// A collection of HTTP method handlers to use by this /// ; - /// or + /// or /// null to use the built-in method handlers. /// /// is null. @@ -88,8 +88,8 @@ namespace WebDAVSharp.Server { } /// - /// Gets the - /// that this + /// Gets the + /// that this /// uses for /// the web server portion. /// @@ -131,7 +131,7 @@ namespace WebDAVSharp.Server { } ///// - ///// Starts this + ///// Starts this ///// and returns once it has ///// been started successfully. ///// @@ -162,7 +162,7 @@ namespace WebDAVSharp.Server { //} /// - /// Starts this + /// Starts this /// and returns once it has /// been stopped successfully. /// @@ -232,10 +232,10 @@ namespace WebDAVSharp.Server { //TODO: (Charly): enable authentication // For authentication - Thread.SetData(Thread.GetNamedDataSlot(HttpUser), context.User.Identity); + Thread.SetData(Thread.GetNamedDataSlot(HttpUser), context.User?.Identity); _log.Info(context.Request.HttpMethod + " " + fileName); - Trace.WriteLine($"\nWebDAV - {context.Request.HttpMethod} - {fileName} - {context.User.Identity.AuthenticationType}: {context.User.Identity.Name}", "Info"); // + _log.Debug($"WebDAV - {context.Request.HttpMethod} - {fileName} - {context.User?.Identity?.AuthenticationType}: {context.User?.Identity?.Name}"); try { try { string method = context.Request.HttpMethod; @@ -289,7 +289,7 @@ namespace WebDAVSharp.Server { string headers = ""; try { foreach (var key in context.Response.Headers.AllKeys) { - headers += $"\t{key}: {context.Response.Headers[key]}\n"; + headers += $"\t{key}: {context.Response.Headers[key]}\n"; } } catch (Exception ex) {