In IIS 7.0 HttpContext.Current property in Application_Start cannot be accessed

Hi,

One of the major changes in IIS 7.0 is that the HTTP context is not available in the application_start event. If you try to work with the http context (with the help of Httpcontext.current) in the application_start event in global.asax then you will receive an ASP.NET 500 – Server Error: Request is not available in this context.

In IIS 7.0 the Application Initialization has been decoupled from the request that has triggered the application start and hence the request is not available in the vent. In the classic mode , it was possible for us to indirectly access the request as the Asp.net initialization directly coupled with the request for which the application was started.

The problem can easily be worked with a workaround by using a static constructor, which is fired when the object is accessed first. We can keep a flag in the Application_Beginrequest event and easily determine the request that initialized the application.

Vikram


Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Posted on 3/18/2008 11:28:49 AM

Hi Vikram,

I saw your web site and impressed with the articles you posted.
I am having ptoblem with my IIS 2.05.... When I deoploy my service in my local host and try to access the serive with http:\\localhost\service.svc or service.asmx it gives below error.

"SERVER application error"
when I look into the event log gives the detail error shown below
"The server failed to load application '/LM/W3SVC'. The error was 'The specified metadata was not found.
'.
For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
"
your help will be greatly appreciated.

thanks,
Anil

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2008 Vikram Lakhotia