AppCmd Migrate Config and HTTP Error 500.22

Tags: .NET, ASP.NET

Yesterday I tried to migrate an Web Application from IIS 6 to IIS 7 integrated managed pipeline mode. After copying the files to the new folder I opened a Web browser and got following error message:

IIS 7.0 - Detaillierter Fehler - 500.22 - Internal Server Error - Internet Explorer bereitgestellt von DellHTTP Error 500.22 - Internal Server Error

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.

Most likely causes:

  • This application defines configuration in the system.web/httpModules section.

Things you can try:

  • Migrate the configuration to the system.webServer/modules section. You can do so manually or by using AppCmd from the command line - for example, %SystemRoot%\system32\inetsrv\appcmd migrate config "Default Web Site/". Using AppCmd to migrate your application will enable it to work in Integrated mode, and continue to work in Classic mode and on previous versions of IIS.
  • If you are certain that it is OK to ignore this error, it can be disabled by setting system.webServer/validation@validateIntegratedModeConfiguration to false.
  • Alternatively, switch the application to a Classic mode application pool - for example, %SystemRoot%\system32\inetsrv\appcmd set app "Default Web Site/" /applicationPool:"Classic .NET AppPool". Only do this if you are unable to migrate your application.
(Set "Default Web Site" and "Classic .NET AppPool" to your application path and application pool name)

Since IIS 7 you’ll get more richer error messages and things you can try. In the lower section you’ll find as first step you can try to run AppCmd with the migrate option. I simply copied the command in a command box, hit enter and got an error message that there is no Default Web Site. Ah, I can remember, I changed the name of the Web site some weeks before so I have to check for the real name of the Web site. As the IIS knows the real name the error message could contain the name already. Running AppCmd again with the correct name was working, now.

When trying to start my Web Application I noticed that I got some JavaScript error messages and that some of my HTTP handlers are not working. A deeper look inside my migrated changed web.config I noticed that AppCmd didn’t migrate my HTTP handlers.

My old HTTP handler configuration looks like this:

<httpHandlers>
    <add verb="GET" path="ScriptEngine.ashx" type="AjaxPro.Web.ScriptEngineHandler,AjaxPro" />
    <add verb="*" path="*.ashx" type="MS.Web.PageHandlerFactory,PcTopp.Library" />
</httpHandlers>

AppCmd creates the new system.webServer section at the end of the web.config file with following configuration:

<handlers>
    <add name="*.ashx_*" path="*.ashx" verb="*" type="MS.Web.PageHandlerFactory,PcTopp.Library" preCondition="..." />
    <add name="ScriptEngine.ashx_GET" path="ScriptEngine.ashx" verb="GET" type="..." preCondition="..." />
</handlers>

Notice that the lines are interchanged and the ScriptEngine.ashx will never be executed, now. The ScriptEngine in my project will offer JavaScript file packages that are compressed and optimized for each section of the application.

Another problem I had to fix manually are all of my location tags. The AppCmd migrate process didn’t change any of them:

<location path="ajaxpro">
  <system.webServer>
    <handlers>
      <add name="AjaxPro" verb="GET,POST" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro" />
    </handlers>
  </system.webServer>
  <system.web>
    <httpHandlers>
      <add verb="GET,POST" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro" />
    </httpHandlers>
    <authorization>
      <allow users="?" />
    </authorization>
  </system.web>
</location>

I have left the old httpHandlers tags that the same web.config is still working on IIS 6.

No Comments