如何使用 HTTP subStatus 在 Classic ASP 中发送 HTTP 错误代码?

How to send HTTP error code in Classic ASP with a HTTP subStatus?

在经典 ASP 中,我知道可以通过指定 return HTTP 错误 Header .Status 属性,像这样:

Response.Status = "404 File Not Found"

但是我如何 return 更具体的错误代码 和子状态 ,例如 404.9 或 500.100?

出于测试目的我需要这样做(因为我知道 subStatus 代码通常由服务器动态添加)

IIS 不会在流量日志中记录自定义子代码。

不测试子代码。测试自定义错误返回的 statusText 属性。

所以:似乎只能从经典 ASP 代码生成 "three-digit" HTTP 错误。

因此,测试自定义网页是否正常工作的唯一方法是调用网站上的 "test.yyy" 文件

由于文件扩展名 .yyy 不是 IIS MimeMap 的一部分,静态文件处理程序将不会为其提供服务,然后 return 出现 404.3 错误。这样,我就可以测试我的自定义错误页面。 此示例来自这篇 Microsoft 文章:https://www.iis.net/learn/troubleshoot/diagnosing-http-errors/how-to-use-http-detailed-errors-in-iis

因此,对于需要在 IIS 7 / 8 下设置非常详细的错误消息(包括 HTTP 子代码)的每个人,这里是您网站的 "web.config" 文件内容:(这个文件只包含几个条目,但你显然可以为你想要的每个 HTTP code/subcode 组合添加条目。微软在 C:\inetpub\custerr 中提供了 56 个错误页面)

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpErrors errorMode="Custom">
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" subStatusCode="5" prefixLanguageFilePath="" path="E:\inetpub\vhosts\yourdomain.com\error_docs4-5.html" />
            <error statusCode="404" subStatusCode="4" prefixLanguageFilePath="" path="E:\inetpub\vhosts\yourdomain.com\error_docs4-4.html" />
            <error statusCode="404" subStatusCode="3" prefixLanguageFilePath="" path="E:\inetpub\vhosts\yourdomain.com\error_docs4-3.html" />
            <error statusCode="404" subStatusCode="2" prefixLanguageFilePath="" path="E:\inetpub\vhosts\yourdomain.com\error_docs4-2.html" />
            <error statusCode="404" subStatusCode="1" prefixLanguageFilePath="" path="E:\inetpub\vhosts\yourdomain.com\error_docs4-1.html" />
            <error statusCode="404" subStatusCode="0" prefixLanguageFilePath="" path="E:\inetpub\vhosts\yourdomain.com\error_docs4-0.html" />
        </httpErrors>
    </system.webServer>
</configuration>

希望对您有所帮助! :)