views:

149

answers:

1

I have an ASP.NET Web Application project that used to target ASP.NET 2.0. I installed ASP.NET 4.0 on the web server hosting the web application and changed the web application project to target .NET 4.0. Everything works ok with on exception: Custom Error Handling

Before migrating to .NET 4.0, custom errors used to work. In my application I have a Global.asax page with a global application error handler which works fine on my development environment (and worked just fine with .NET 2.0 on the server as well) which doesn't work with the new IIS 7 with .NET 4.0 setup. I also have a customErrors section in the web.config file which is supposed redirect the browser to a custom error page in case the error was such that even the global application handler would fail. That also works fine on my machine, but fails to do anything on the server. And I did try all three different settings for the mode attribute.

If anyone has any idea why this might be happening I'd appreciate any feedback!

A: 

This one is still a bit mysterious but here's what I found. My error handlers were all firing, and the redirects were happening just as before but when the request was finally transferred to the error handler .aspx page (via a Server.Transfer) it was dying. The reason for that was that on the ErrorHandler.aspx page, I was setting the HTTP response code to 200, trying not to send back an actual HTTP error code, and instead to simply display a friendly message. Once I commented out the code that was setting the HTTP Status code to 200, all started working fine and almost like before the move to .NET 4.0.

I'm still not sure why attempting to set the HTTP Status code to 200 was causing the strange behavior, but I'm glad I found it, corrected the problem and could get on with my life..

Miky Dinescu