How to get Custom Error Pages working for Classic ASP with IIS 7 Integrated Pipeline

我们两清 提交于 2019-12-21 02:46:16

问题


I'm working on a website with legacy Classic ASP pages (being converted to ASP.NET on an as needed basis) and new ASP.NET pages. Use of IIS 7 Integrated Pipeline has been very helpful with our configuration. For example, we were able to get forms authentication working auto-magically with the classic ASP pages simply by configuring the appropriate sections of the web.config file (i.e. no changes were required to the Classic ASP pages, for more info see this).

A colleague of mine believes that custom error pages, as specified in the web.config <customErrors> section, should also be auto-magically applied to the classic ASP pages, but for our website it only works for the ASP.NET pages. Nor have I been able to find any information describing the capability of applying custom error pages to Classic ASP with the IIS 7 integrated pipeline.

Is it possible to apply custom error pages to Classic ASP pages per a web.config for an website running under IIS7 with integrated pipeline? If so, how?


回答1:


The IIS7 custom error pages are handled in the <system.webServer> configuration section not the <customErrors> section under <system.web> which applies to ASP.NET only:

<configuration>
    <system.webServer>
        <httpErrors>
            <error 
               statusCode="500" 
               subStatusCode="100" 
               path="/500errors.asp" 
               responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>

Beware though of these settings conflicting with ASP.NET custom errors. If you're running .NET 3.5 and above you can set Response.TrySkipIisCustomErrors in your ASP.NET error page code-behind (or error controller if using MVC) to prevent IIS overriding your ASP.NET error page(s):

Response.TrySkipIisCustomErrors = true // ASP.NET Forms

This article by Rick Strahl explains this problem in a bit more depth:

IIS 7 Error Pages taking over 500 Errors



来源:https://stackoverflow.com/questions/3874353/how-to-get-custom-error-pages-working-for-classic-asp-with-iis-7-integrated-pipe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!