简体   繁体   English

如何使 IIS7 提供状态码为 404 的自定义内容

[英]How to make IIS7 serve custom content with status code 404

I have a classic ASP page that sets the response header to 404 Not Found plus some you might be interested in links:我有一个经典的 ASP 页面,它将响应标头设置为404 Not Found以及一些您可能对链接感兴趣的链接:

Response.Clear
Response.Status = "404 Not Found"
Response.Write "<h1>Oops</h1>"
Response.Write "<p>The page you requested was not found</p>"
Response.Write "<p>But we have some suggestions:</p>"

This code ran fine on IIS6 ie it sent correct response code plus the content.这段代码在 IIS6 上运行良好,即它发送了正确的响应代码和内容。 However, on IIS7, all I get is this:但是,在 IIS7 上,我得到的只是:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.您要查找的资源已被删除、更名或暂时不可用。

How can I make IIS show my content without changing configuration (if possible).如何在不更改配置的情况下让 IIS 显示我的内容(如果可能)。

Firstly, ensure that the application pool for the site is running in "Classic Mode".首先,确保站点的应用程序池在“经典模式”下运行。 To set this, select the application pool for the site in IIS, click "Basic Settings..." and set "Managed pipeline mode" to "Classic".要设置此项,请在 IIS 中为站点选择应用程序池,单击“基本设置...”并将“托管管道模式”设置为“经典”。

Next, select the site in IIS and, click the "Error pages" icon.接下来,在 IIS 中选择站点,然后单击“错误页面”图标。 Click "Edit Feature Settings..." and make sure "error responses" is set to "Custom Error Pages".单击“编辑功能设置...”并确保“错误响应”设置为“自定义错误页面”。

You should then find you can set the 404 error to execute your ASP page.然后你应该会发现你可以设置 404 错误来执行你的 ASP 页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM