Is HttpContext.Current Ever Null in a web app?

Is HttpContext.Current ever null in a web app (if no streams are used)? More specifically, will it ever be null in void Application_OnError(object sender, EventArgs e)

?

+2


source to share


3 answers


see this other question

The session is not initialized until the AcquireRequestState event, so any error that occurs up to that point will have no session variables available.



I think the same applies to HttpContext.Current as HttpContext.Current.Session

So yes, I think HttpContext.Current can sometimes be empty in Application_OnError

+2


source


I believe this can happen if, for example, you disconnect 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.



+1


source


There have been some interesting changes with IIS 7. In IIS6, you had HttpContext in Application_Start. Starting with IIS7, this is no longer the case.

Additional Information:

http://blogs.msdn.com/webtopics/archive/2009/02/12/webbaseevent-raise-method-fails-in-application-start-event-with-a-nullreferenceexception-on-iis-7-0. aspx

-Oisin

+1


source







All Articles