Reputation: 6981
Is HttpContext.Current ever null in a web Application (assuming threads are not being used)? More specifically, would it ever be null in void Application_OnError(object sender, EventArgs e)
?
Upvotes: 2
Views: 2364
Reputation: 52480
There were some interesting changes in IIS 7 with respect to this. In IIS6, you had a HttpContext in Application_Start. From IIS7 onwards this is no longer the case.
More Information:
-Oisin
Upvotes: 2
Reputation: 19870
I believe it can happen if, for example, you spin off a worker thread, the response ends, and the worker thread throws an exception. Your Application_OnError will catch the exception, but the HttpContext.Current will be null.
Upvotes: 1
Reputation: 23064
Session is not initialized until the AcquireRequestState event, so any error occurring before this point will not have session variables available.
I think the same applies to HttpContext.Current as HttpContext.Current.Session
So yes, I think HttpContext.Current can sometimes be null in Application_OnError
Upvotes: 3