Migration to IIS7: Server Error in '/' Application

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

While migrating of your ASP.NET application from IIS6.0 or Casini to IIS7.0 you may run into several problems. Because the architecture of IIS has been changed, there are few things you have to be aware of. I'm not going to describe all of them in detail in this post, but I will point few of them which made most problems to me.

Internal Server Error Issue

After publishing of your ASP.NET application (I.e.: within Visual Studio) the application may not start if some handlers and/or modules have been registered in the web.config file. Usually, they are registered in the section system.web as shown in following example:

<system.web>
<httpHandlers>
<
remove verb="*" path="*.asmx" />
<
add verb="*" path="*.asmx" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35
" />

</httpHandlers>
<
httpModules>
<
add name="ScriptModule"
type="System.Web.Handlers.ScriptModule,
System.Web.Extensions,
Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35
"
</httpModules>

</system.web>

However, IIS7.0 "Integrated Pipeline" requires registration of handlers within the section: system.webServber. When the application is started following error may appear:

HTTP Error 500.0 - Internal Server Error

Description: This application is running in an application pool that uses the Integrated .NET mode. This is the preferred mode for running ASP.NET applications on the current and future version of IIS.
To repair this automatically use following statement:
%systemroot%\system32\inetsrv\APPCMD.EXE migrate config "YourVirtualAppEntry/"

After executing this statement, the previous section will look like:

<system.webServer>
<httpModules>
<
add name="ScriptModule"
type="System.Web.Handlers.ScriptModule,
System.Web.Extensions,
Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35
"
</httpModules>
<
httpHandlers>
<
add verb="*" path="*.asmx" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35
" />

</httpHandlers>
</
system.webServer>


RequestContext Issue

Probably most often error which occurs by migration is:

Request is not available in this context
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Request is not available in this context

In general this error is not a bug. It may sound funny, but it is a new feature of IIS7. Previously, while starting web application in Globa.asax it was possible to access the Request instance within context of "Application_Start" handler. In IIS7 this is no more possible, because the context of very first request which starts the web application does not exist while application is starting. Personally, I find this design better than the previous one. I was always asking myself, how it is possible to obtain the instance of the request before the handler Application_BeginRequest has even be invoked?
Now, if you need the Request context you can obtain it after the execution path entered Application_BeginRequest handler in Global.asax.

Unfortunately, it seems that Microsoft did not remove completely the dependency of Request-Context in its own ASP.NET code. For example following configuration will cause you application to fail if started in IIS7.

<globalization culture="auto:de-DE" uiCulture="auto:de-DE"></globalization>

If you use this configuration you will get the same error "Request is not available in this context". The bad thing is that you generally have no influence on this. The good thing is that the workaround in this specific case is very simple:

<globalization culture="de-de" uiCulture="de" />

An Intersting into in IIS7 can be found here: 


Posted Dec 20 2007, 11:55 PM by Damir Dobric
Filed under:
developers.de is a .Net Community Blog powered by daenet GmbH.