IIS
ASPNET MVC IIS7 and Bad Request
May 1st
While working on an app recently I ran into the issue of needing to handle httpErrors at runtime in a dynamic fashion. I did this with some custom controller execution and routing.
If a user were to type in an invalid address a custom 404 would be returned.
Example: http://example.org/foo
The Problem
Unfortunately my custom error handling code was working in Cassini but in IIS7 it was not.
IIS 7 would return “Bad Request”. Here is how I fixed it.
The problem was that I was not telling IIS7 what to do with httpErrors.
The Fix
You can enable this by doing so in the web.config:
<system.webServer>
<httpErrors errorMode=”Detailed” />
</system.webserver>
To use this option you will need to unlock this config section for IIS7. To do this, open the command prompt on the IIS7 box and execute the following command:
%windir%\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/httpErrors
or if you want to unlock the config section for just a particular site, execute this:
%windir%\system32\inetsrv\appcmd.exe unlock config "SiteName/app/url" -section:system.webServer/httpErrors
I was now able to handle the http errors returned from IIS7.
ASP.NET App – is not a valid Win32 application
Mar 24th
Never seen this one before until this morning. Well, I’ve seen the “not a valid Win32 application” error a ton of times, but this is the first time on with an ASP.NET app (running MVC).
How to Fix
If you ever see this and your app is running IIS7, here’s the first thing to check:
- Inside IIS (7) click on Application Pools.
- Find the Application Pool that is configured for your web application in the list.
- Select it, then click Advanced Settings on the right.
- Second setting in the list: Enable 32-Bit Applications – must be set to True.
That should get you up and running again. I have no idea how my app pool changed from 32 to 64 unless another dev accidentally changed it.
Why
The reason the 64bit setting wont work? Here’s what I’ve determined from my reading – On a 64-bit Windows machine the World Wide Web Publishing service does not support running 32-bit and 64-bit worker processes concurrently on the same server, which is what happened above.
IIS 7 – This configuration section cannot be used at this path.
Mar 26th
If you’re new to IIS 7 (you probably are) you might receive this nice little gem when you first start working with it:
HTTP Error 500.19 – Internal Server Error
Description: The requested page cannot be accessed because the related configuration data for the page is invalid.
Error Code: 0×80070021
Notification: BeginRequest
Module: IIS Web Core
Requested URL: http://localhost:80/ExampleApplication/
Physical Path: C:\inetpub\wwwroot\ExampleApplication\
Logon User: Not yet determined
Logon Method: Not yet determined
Handler: Not yet determined
Config Error: This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=”Deny”), or set explicitly by a location tag with overrideMode=”Deny” or the legacy allowOverride=”false”.
FONT color=#a52a2a>
Config File: \\?\C:\inetpub\wwwroot\ExampleApplication\web.config
Config Source:
184: </modules>
185: <handlers>
186: <remove name="WebServiceHandlerFactory-Integrated"/>
184: </modules>
185: <handlers>
186: <remove name="WebServiceHandlerFactory-Integrated"/>
IIS 7 implements “Configuration Locking“. This is to help with IIS administration. The IIS Administrator can lock down Configuration Sections, Section Elements and Attributes at the IIS level. This allows the administrator to have a more granular level of control on the system. Read this link to see more about it.
Important Note: In order make these changes, you must be an administrator on the machine where the config file resides. If its on your local machine, you must be an administrator on your machine.
Since I’m on my own development machine, and since this is a development machine, I have decided to change the global setting (the config section itselft). To fix this error I had to go to the applicaitonHost.config file and set the overrideModeDefault to “Allow”.
Here’s how:
Open the applicationHost.config file, located here: %windir%\system32\inetsrv\config\applicationHost.config
In my instance, I need to edit the “handlers” section.
Change this line:
<section name=”handlers” overrideModeDefault=”Deny” />
To:
<section name=”handlers” overrideModeDefault=”Allow” />
Thats it.
You might receive more errors after you enable this, such as the same error for modules, but just follow the same steps above, and you should be good.
Note: You can accomplish this same thing through the command line by using the appcmd.exe application (%windir%\system32\inetsrv\appcmd.exe). Like this:
%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/handlers
One more note…
This is not something you’d want to do on a production server unless you’re sure you want to enable all appliations to override the section contents. Be sure to read up on some of the docs (explanation of the configuration system) before you make this change on production.