views:

516

answers:

3

I have asp.net site with custom 404.htm. It is configured with customErrors section to handle aspx.

<customErrors mode="On" defaultRedirect="404.htm">
<error statusCode="403" redirect="404.htm" />
<error statusCode="404" redirect="404.htm" />
</customErrors>
<system.webServer>
<httpErrors>
<error statusCode="404" path="404.htm" />
<error statusCode="500" path="404.htm" />
</httpErrors>
<modules runAllManagedModulesForAllRequests="true"> ...
</system.webServer>

It handles wrongname.aspx well. But for non-aspx requests such as wrongname.htm IIS7 still returns generic error message, not my custom. How to force him do that, say, for all errors for this site, including 500? Should I write a module or it is possible declaratively?

A: 

You can set custom error pages for most of the HTTP errors through the IIS settings for your website. (In IIS 5 this is the Properties->Custom Errors tab, not sure where you'd find it for IIS7)

Mark
A: 

In order for the custom 404 to apply the approrpiate bit of IIS has to be set up to handle the extension that you are using.

For the integrated pipeline in IIS7 I thought (though IIS7 makes one's life interesting) that the default was to process all extensions.

First check whether you've got the app running in Classic or Integrated - if the former then that will be part of the problem, if the latter.... I have to work this out every time (I don't do it enough).

Murph
A: 

When testing locally, iis7 will tend to show you a generic error message unless you add an attribute to httpErrors, errorMode="Custom". You'll need to edit C:\Windows\System32\inetsrv\config\applicationHost.config to allow this.

Brian