Monday, December 28, 2009

IIS 7 – Managed pipeline mode – Global.asax redirect not working

I installed Windows 7 and I really like it. I migrated all my applications from my old machine to new. And my old machine is running WS 2003 [iis 6] and new machine is Windows 7 [IIS 7]. In all applications everything ran successful except one. I implemented exception handling in my application. I have Global.asax page and in the Application_Error event, I log the exception details and redirecting the user to the error page. Whenever there is an exception in my application the page never redirect to the error page, it stays there in the same page with exception details on the screen.

The same code ran very successful on my old server and in Windows 7 it's not. I just started thinking what could be the issue. The analysis went in this way. Code not changed, DB not changed and the only part changed is the IIS. Windows 7 has IIS7. So, The problem would be either the isapi dll or the application pool. So, started researching on those and found interesting points.

In IIS 7, application pool has a separate feature named "Managed pipeline mode". This will tell the pool the pipeline mode. [which is of type sint32 in c# and the possible values for it are 0 and 1.]

  • 0 is managed pipeline runs in integration mode.
  • 1 is managed pipeline runs in classic or ISAPI mode. [IIS 6].

In Classic mode, managed application events are executed by using ISAPI. In Integrated mode, ASP.NET request processing integrates directly into the IIS 7 request-processing pipeline. Integrated mode enables you to configure managed modules for Web sites that are developed with unmanaged code.

So, to work your logic correct, go to your site and see under what application pool your site running. Now, go to that application pool, properties and change the pipeline mode to classic mode. Now, you see everything works fine and the page starts redirecting to error page when any exception in your application.

For more details: http://msdn.microsoft.com/en-us/library/microsoft.web.administration.managedpipelinemode.aspx

Hope this helps and new tip today. Do you like this post?

8 comments:

  1. Holy moly, thanks so much for the information here! I've just moved our web software from an IIS6 box to IIS7 - low and behold, exception handling fell over.

    I'd have lost more hair if I hadn't found your post! Thanks!

    ReplyDelete
  2. you are an amazing human being! thanks!

    ReplyDelete
  3. Hey man its amazing I helped me lot.
    Thank you thank you very much.

    ReplyDelete
  4. I am facing this problem Although I am using II6. Can you help me? Application_Error hits and works fine when on localhost however it does not work when publish on ii6
    Thanks

    ReplyDelete
  5. What would be more useful is instructions on how to enable these redirects in managed pipeline mode.

    ReplyDelete
  6. The answer is to use HttpContext.Current.ClearError() after you have handled the error to avoid a further redirect to the unwanted ASP.net generic error message page. You may also need

    in the web config. You need to allow this config section change using command prompt. This way you still get the benefits of managed pipeline mode.

    ReplyDelete
  7. Almost two years later and I just want to say that codefish's suggestion of ClearError() worked for me.

    ReplyDelete
  8. I was searching this for past three days and finally got the solution. Thank you so much praveen and Codefish.. :-)

    ReplyDelete