如何使用 IIS 7 集成管道获取适用于经典 ASP 的自定义错误页面 [英] How to get Custom Error Pages working for Classic ASP with IIS 7 Integrated Pipeline

查看:43
本文介绍了如何使用 IIS 7 集成管道获取适用于经典 ASP 的自定义错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个包含旧版经典 ASP 页面(根据需要转换为 ASP.NET)和新 ASP.NET 页面的网站.IIS 7 集成管道的使用对我们的配置非常有帮助.例如,只需配置 web.config 文件的适当部分,我们就可以让表单身份验证自动神奇地与经典 ASP 页面一起工作(即无需对经典 ASP 页面进行任何更改,有关详细信息,请参阅 这个).

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

我的一位同事认为自定义错误页面,如 web.config <customErrors>部分,也应该自动神奇地应用于经典的 ASP 页面,但对于我们的网站,它只适用于 ASP.NET 页面.我也找不到任何描述使用 IIS 7 集成管道将自定义错误页面应用于经典 ASP 的能力的信息.

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.

对于在具有集成管道的 IIS7 下运行的网站,是否可以根据 web.config 将自定义错误页面应用于经典 ASP 页面?如果是这样,怎么做?

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?

推荐答案

IIS7 自定义错误页面在 配置部分而不是 <system.web> 下的 部分,仅适用于 ASP.NET:

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>

请注意这些设置与 ASP.NET 自定义错误相冲突.如果您运行的是 .NET 3.5 及更高版本,则可以设置 Response.TrySkipIisCustomErrors 在您的 ASP.NET 错误页面代码隐藏(或错误控制器,如果使用 MVC)中,以防止 IIS 覆盖您的 ASP.NET 错误页面(s):

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

Rick Strahl 的这篇文章更深入地解释了这个问题:

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

IIS 7 错误页面超过 500 个错误

这篇关于如何使用 IIS 7 集成管道获取适用于经典 ASP 的自定义错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆