Search code examples
c#nullelmahhttpcontextrequest.servervariables

How do I get server variables (or at least client IP address) in C# in Elmah's ErrorMail_Mailing event when HttpContext.Current is null?


I am working on some error handling code and I want to determine if its a local connection (developer) or not. Typically I look at HttpContext.Current.Request.ServerVariables however in the error handling code if authentication expired HttpContext.Current is null.

When HttpContext.Current is null, how do I go about getting the server variables--or at least the IP address of the client that kicked off the request--so I can determine if its a developer on their own local server or not.

UPDATE: I was able to retrieve the relevant server variables in the ErrorMailEventArgs parameter passed in by elmah, specifically errorMailEventArgs.Error.ServerVariables.


Solution

  • I was able to retrieve the relevant server variables in the ErrorMailEventArgs parameter passed in by elmah, specifically errorMailEventArgs.Error.ServerVariables.