Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

HttpModule and HttpHandler sections in IIS 7 web.config files


:P
On this page:

If you have something like the following in your IIS 7 web.config file:

<system.web>
  <httpModules>
     <add name="wwScriptCompressionModule" type="Westwind.Web.Controls.wwScriptCompressionModule,jquerycalendar" />
  </httpModules>
</system.web>
<system.webServer>
    <modules>
      <add name="wwScriptCompressionModule" type="Westwind.Web.Controls.wwScriptCompressionModule,jquerycalendar" />
    </modules>
</system.webServer>

you've probably seen the IIS 7 Exception that lets you know that in Integrated mode in IIS 7 you are not supposed to have an httpModules or httpHandlers section in <system.web>:

Server Error in Application "West Wind Dev/jQueryWeb"


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.
In this mode, the application should not specify ASP.NET module components in the <system.web>/<httpModules> configuration section. Instead, it should use the <system.webServer>/<modules> configuration section to load ASP.NET module components. You have the following options:

1) Migrate the application to work with the Integrated .NET mode (PREFERRED).
You can migrate the application configuration, including the contents of the <httpModules> configuration section, by using the following from a command line window (the window must be running as Administrator):
%systemroot%\system32\inetsrv\APPCMD.EXE migrate config "West Wind Dev/jQueryWeb"
After you migrate your application, it will run in both Classic and Integrated .NET modes, as well as on downlevel platforms.
2) Move this application to an application pool using the Classic .NET mode.
You can move the application to the default application pool using the Classic .NET mode by running the following from an command line window (the window must be running as Administrator):
%systemroot%\system32\inetsrv\APPCMD.EXE set app "West Wind Dev/jQueryWeb" /applicationPool:"Classic .NET AppPool"
Alternatively, you can use any other application pool on your system that is running in the Classic .NET mode. You can also use the IIS Administration tool to move this application to another application pool.
It is preferred that you migrate this application by using option 1 to take advantage of the benefits provided by the Integrated .NET mode.

Error Code: 0x80070032

Notification: BeginRequest

Module: ConfigurationValidationModule

Requested URL: http://localhost:80/jqueryWeb/jQueryCalendar.aspx

Physical Path: c:\projects2008\articles\jQueryWeb\jQueryCalendar.aspx

Logon User: Not yet determined

Logon Method: Not yet determined

Handler: PageHandlerFactory-Integrated

Most likely causes:

  • IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
  • IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
  • IIS was not able to process configuration for the Web site or application.
  • The authenticated user does not have permission to use this DLL.
  • The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

What you can try:

  • Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.
  • Check the event logs to see if any additional information was logged.
  • Verify the permissions for the DLL.
  • Install the .NET Extensibility feature if the request is mapped to a managed handler.
  • Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

More Information... This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error.

Microsoft Knowledge Base Articles:

  • 294807

Server Version Information: Internet Information Services 7.0.

If nothing else you gotta give it to IIS 7 - the error messages it fires are very descriptive and point right at the problem.

Anyway if you see this error you're running IIS 7 in integrated mode and you have an <httpHandler> or <httpModule> definition set up in your <system.web> section of your web.config file. It doesn't matter if you have a <module> or <handlers> section set up in <system.webserver> (which is the IIS 7 server configuration section). Unless you remove the system.web handlers and modules the above error occurs.

This can be annoying if you're moving between two machines that run IIS 5/6 and IIS 7. For example, I do all of my dev on Vista with IIS 7 but my Web Server runs IIS 6 on Windows 2003. It's also problematic if you send sample code out that 'should just run'.

After a discussion earlier today I was pointed at a switch by Ryan Trudelle-Schwarz which allows you to have modules and handlers defined in both places so your code won't break under IIS 7:

<system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>
  <modules>
    <add name="wwScriptCompressionModule" 
         type="Westwind.Web.Controls.wwScriptCompressionModule,jquerycalendar" />
  </modules>
</system.webServer>

With this flag in place IIS 7 won't validate httpModules and httpHandlers in system.web and won't throw the exception page that you need to migrate your handlers. And thankfully this flag works at the web.config level!

The configurability on IIS 7 comes through again.

Posted in IIS  IIS7  

The Voices of Reason


 

Mike Volodarsky
October 11, 2007

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

Right on!

When we made the Integrated pipeline the default for ASP.NET applications on Windows Vista and beyond, making sure that apps continue to work correctly was our biggest concern.

Having the modules and handlers listed in the new IIS configuration was a major potential breaker, I wanted to be very very clear about it and make sure people couldnt just let a legacy app run in Integrated mode and be missing its modules or handlers. Hence the detailed error message, and the built-in migration support in AppCmd.

The Vista error message is even better then Windows Server 2008, since it actually gives you the exact command to migrate (copy paste baby!). On server, the message had to be changed and just gives an example, but by this point people should already be more comfortable with the whole thing.

There is a little bit more background in the ASP.NET Integration article: http://www.iis.net/default.aspx?i=928&subtabid=25&tabid=2&p=2.

Thanks,

Mike

Rick Strahl
October 11, 2007

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

Thanks for the background Mike. I'm just glad that this option is settable at web.config level without any problems. Too many of the other 'override' switches are defaulted to non-overridable in Applicationhost.config.

I'll definitely be using this switch in just about any demo app <g>...

Durbs
November 12, 2007

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

Nice find there Rick, had the same problem with an app i send to clients and was having to instruct them to alter their web.config settings depending on what flavour of IIS they were using. Often ended in confusion as you can imagine!

Advanced Technology
February 29, 2008

# Testare un HttpHandler in ClassicMode

Testare un HttpHandler in ClassicMode

Stefan Vantchev
April 08, 2008

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

Dear Rick,
lets see if you can help out with this one...
I have a custom control that has a designer that updates the web.config of the host web application. It registers a custom http handler that is part of the custom control assembly.
(see http://www.tkachenko.com/blog/archives/000686.html for more information)

Now, this worked perfectly until IIS7. I can't seem to be able to get ahold of the system.webServer section to add a handler in design time. Any thoughts??

Thanks
Stefan

Dheeraj
May 11, 2009

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

The above solution didnt work for me. I have it exactly like the way the article is described but didnt work. The only thing i wanted to point out is that my root website is at 64 bit meaning Enable 32 Bit App is set to False.

Mihir Mone
June 29, 2009

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

I am working on Url Rewriting for my web application in ASP.net 2.0 with IIS7.
I created HttpModule. When I try and register it under <system.webServer>, I dont get <modules> section listed in the intellisence.

I want to invoke that module for paths like (*) -
http://mysite/mihir (will redirect to - http://mysite/employee.aspx?name=mihir)

Am I doing anything wrong?

Matt
September 15, 2009

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

The above solution worked a charm for me:

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>

Thanks,

Matt

Andrewiski
September 16, 2009

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

Once again Rick you save me a lot of work. Thanks for the Post. I hate having two webconfigs and having to switch them to handle different IIS versions.

Andy

gices
October 03, 2009

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

Even with <validation validateIntegratedModeConfiguration="false"/>, my httpmodule does not seem to be kicking in. I'm testing on vista, .net framework 3.5, any pointers?

Yuvraj
December 15, 2009

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

All the comments and code display in this disuccion is true but when i tried the combining the single web config for IIS6 and IIS7 we can use the both the handlers for settting more secure config file need to study details as per required environment.
Before going for actual setting I would like to suggest please go through the following link foum on one forum for more detail
http://www.infosysblogs.com/microsoft/2007/02/configuring_custom_http_handle.html

Noel
December 16, 2009

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

This was so helpful to me!! When I first converted to IIS7 I actually didn't even see an error page, just a blank page, maybe because all of my app's pages were handled by httpmodules or httphandlers. Thanks to your post I was able to resolve the problem right away!

Lars
January 03, 2010

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

Hi Rick!

I've come across your site a couple of time over the last months and read some usefull info. Therefore, I would like to mention to you a little thing (or even a bug) I've seen...

I wanted to share sessions between webapps on the same server / URL / domain, with IIS7. I found a solution on codeplex http://www.codeproject.com/KB/session/sharedsession.aspx ... it worked perfectly on cavini, but when on local IIS7 webapps (everything the same), it refused.

Seems that IIS7 refuses <system.web><httpModules> implementations, while modules declared in <system.webServer><modules> are processed.

To prove yourself, just download the above session-tweak allowing to share sessions between different apps on the same server (SQL State enabled) - do the above - Cavini works, IIS7 doesn't. Then, just copy-cut the module to the new IIS7-section and it works again.

I think the ELMAH works again too...

And it is a way to avoid having to spend loads of money on 3rd party Cache / Sessionstate software - for the time-being...

Have fun at Hawaii!

Peter Newby
February 11, 2010

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

So many of us owe you sooo much beer! - Thanks.

Carlos
April 23, 2010

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

Great help Rick, as I have been tackling a nasty error with WCF Ria Services for 2 weeks now with no success. Cannot browse to a .svc module with error 404.
Finally came down to taking out the httpmodules from under system.web.

Owen
November 01, 2011

# re: HttpModule and HttpHandler sections in IIS 7 web.config files

When I try to use the migrate option, I get the following error:
ERROR ( message:Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to '*_AppService.axd_*'

Any ideas?

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024