From a380fa6dc295b33f6bd0baec96945e355fa38e21 Mon Sep 17 00:00:00 2001 From: Werner van Deventer Date: Fri, 15 May 2015 19:56:12 +0200 Subject: [PATCH] - Fix for issue #16 Only try to get the application context if the request property is found, otherwise fallback to `HttpContext.Current` as a last ditch attempt at getting a context which could also return `null`. --- src/Elmah.Contrib.WebApi/ElmahExceptionLogger.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Elmah.Contrib.WebApi/ElmahExceptionLogger.cs b/src/Elmah.Contrib.WebApi/ElmahExceptionLogger.cs index 240d2ba..813c23e 100644 --- a/src/Elmah.Contrib.WebApi/ElmahExceptionLogger.cs +++ b/src/Elmah.Contrib.WebApi/ElmahExceptionLogger.cs @@ -29,14 +29,14 @@ private static HttpContext GetHttpContext(HttpRequestMessage request) return null; object value; - if (!request.Properties.TryGetValue("MS_HttpContext", out value)) - return null; - - HttpContextBase context = value as HttpContextBase; - if (context == null) - return null; - - return context.ApplicationInstance.Context; + if (request.Properties.TryGetValue("MS_HttpContext", out value)) + { + HttpContextBase context = value as HttpContextBase; + if (context != null) + return context.ApplicationInstance.Context; + } + + return HttpContext.Current; } } } \ No newline at end of file