5

I have an ASP.NET MVC application which returns 404 and occasionally, 500 status codes at various, appropriate points.

Response.StatusCode = (int)HttpStatusCode.NotFound;

When I set one of these status codes, I also set the TrySkipIisCustomErrors property appropriately.

Response.TrySkipIisCustomErrors = true

What I would like to do now, is configure IIS to pass through these errors, which I am setting myself, and catch any other errors that may occur (such as 404s on static files, where I am not sending requests to ASP.NET, or uncaught 500 errors in my application (where presumably the TrySkipIisCustomErrors propety will not have been set by the framework).

My system.webServer/httpErrors node looks like this:

<httpErrors existingResponse="Auto" errorMode="Custom">
</httpErrors>

This returns my own ASP.NET errors where I set TrySkipIisCustomErrors = true, and the standard IIS error pages for uncaught 500s, static file 404s etc.

I then tried modifying it like this:

<httpErrors existingResponse="Auto" errorMode="Custom" defaultPath="/Skins/Shared/Error/Error.html" defaultResponseMode="ExecuteURL">
  <clear />
</httpErrors>

I believe that this should display my custom error page in place of the standard IIS one. However, when I add this code I get a one line IIS error ("The page cannot be displayed because an internal server error has occurred.") and it returns a 500 status code.

I assume this is due to an error in my configuration, but I can't for the life of me understand what I'm doing wrong!

I have also tried this approach, with the same results:

<httpErrors existingResponse="Auto" errorMode="Custom" defaultPath="Skins\Shared\Error\Error.html" defaultResponseMode="File">
  <clear />
</httpErrors>

Even setting a redirect to a completely different URL produces the same problem.

I have been using this page among others for reference: http://blogs.iis.net/ksingla/archive/2008/02/18/what-to-expect-from-iis7-custom-error-module.aspx.

The error file definitely exists, and I am able to hit it directly using a browser.

As an aside, I'm not entirely sure what I should be doing with the system.Web\customErrors node. Is this an IIS6 only setting, or does it somehow relate to ASP.NET? Currently I do not include it in my web.config.

jamiecon
  • 1,770
  • 3
  • 19
  • 32
  • Did you manage to figure this out? I have the same problem :s – Robba Apr 15 '11 at 14:22
  • What errors are in the Windows Event Log? Do you have the application pool `Managed pipeline mode` setting set to `Integrated` or `Classic` mode? (Should be `Integrated` for your scenario.) – Jon Adams Sep 13 '11 at 14:08
  • Application pool is in integrated mode. Still have the issue, and have been unable to find a solution. There are no errors in the Event Log. Pretty frustrating! – jamiecon Sep 14 '11 at 15:34
  • Just revisiting this problem (which still exists on our production application) and the ridiculous thing is, I actually get the error if I just use the IIS GUI to add the file - so it's not like it's some silly typo. – jamiecon Sep 14 '11 at 15:56

2 Answers2

1

add this to your system.webserver node. It will tell IIS to let the errors be handeled by ASP.Net.

<httpErrors existingResponse="PassThrough" />
Khalid Abuhakmeh
  • 10,709
  • 10
  • 52
  • 75
1

I know this is an old question but it's identical to the problem I have been having for the past few days that I just recently figured out. What worked for me:

Try removing the

<httpErrors>

element from web.config entirely.

JPRO
  • 1,062
  • 7
  • 19