English 中文(简体)
Custom 404 page for ASP.net site on IIS7 for non-asp.net URL
原标题:

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?

问题回答

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)

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).

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:WindowsSystem32inetsrvconfigapplicationHost.config to allow this.





相关问题
session transfer issue from Tomcat to ASP.Net

I am using Tomcat to host JSP and using IIS 7.0 to host aspx (C# + .Net 3.5 + VSTS 2008), and I have some session transfer issue from JSP page to ASPX page. JSP page is in one domain and all other ...

How to use appcmd to set debug=false in IIS7

I m trying to use APPCMD to set debug=false in web.config, per the documentation. The specific syntax I am using is: APPCMD SET CONFIG "SITE/VDIR" section:compilation /debug:False /commit:APP ...

Windows User Account that executes only IIS7 Provisions

I have a web application that executes IIS 7 provisions (using Microsoft.Web.Administration.dll) to create our web and ftp sites. When I run this using the administrator account, it works ok. I want ...

Could I get by HttpModule the URL that contains * before?

My web-site is working under ASP.NET 3.5, IIS7, Integrated pipiline mode. My HttpModule is getting request to all resources, including URLs like this: http://my-site.com/address And I would support *...

IIS 7 Http Handler development issue

I am using VSTS 2008 + C# + .Net 3.5 + IIS 7.0 to develop an ASP.Net web site. I want to develop an Http module, which could inspect whether incoming request has some specific http header (e.g. ...

热门标签