使用IIS6而不是web.config设置显示自定义错误页面

时间:2010-01-28 10:49:48

标签: iis-6 web-config custom-errors

这是我关于这个伟大的编程信息来源的第一篇文章。

我为客户开发了新网站,只是做了一些收尾工作。

我正在尝试创建可从 web.config

中读取的自定义错误页面
 <system.web>
 <customErrors mode="RemoteOnly">
           <error statusCode="404" redirect="404.aspx" />
           <error statusCode="500" redirect="500.aspx" />
    </customErrors>

它适用于本地开发机器,并且根据需要显示404和500错误。

在将网站编译并发布到Web服务器后,它无法正常工作。 IIS 6继续显示原始IIS 6错误页面,如404错误:

The page cannot be found

The page you are looking for might have been removed, 
had its name changed, or is temporarily unavailable. 
Please try the following:

Make sure that the Web site address displayed in the address bar of 
your browser is spelled and formatted correctly.

If you reached this page by clicking a link, contact the Web site 
administrator to alert them that the link is incorrectly formatted.

Click the Back button to try another link.
HTTP Error 404 - File or directory not found.
Internet Information Services (IIS)

我不确定为什么会这样做,我认为web.config会覆盖原始的IIS6设置。


好的,我发现问题出在404 .aspx页面上。错误500工作正常并显示500.aspx页面。但不适用于404.aspx。请建议

1 个答案:

答案 0 :(得分:2)

如果请求传递给.NET ISAPI过滤器,则Web配置将仅覆盖IIS6设置 - 例如,对于以.aspx结尾的页面

如果我浏览了一个没有访问.NET ISAPI的文件或目录,则不会使用web.config规则。