我已经尝试了以下(并尝试使用已注释掉的未注释)但只得到一个错误:
您要查找的资源已被删除,名称已更改或暂时不可用.
在已发布的网站项目的web.config中:
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404"/>
<!--<error statusCode="404" responseMode="File" path="\Error\404.htm"/>-->
<error statusCode="404" responseMode="ExecuteURL" path="http://example.com/Error/404.htm"/>
</httpErrors>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
我通过将浏览器中的URL从.../default.aspx(很好)更改为来尝试.../abc.aspx.
这是重定向到错误页面的正确方法,还是有错误?
编辑
我发现如果我尝试http://example.com/nonExistingPage- 它会重定向到错误页面.但不是来自http://example.com/Folder/nonExistingPage
编辑2
通过指定之后的路径可以部分解决问题example.com.但是 - 该网站发布到example.com/subfolder有人导航到的时间example.com/nonExistingFolder- 未显示自定义错误页面.
ksp*_*rin 11
试试这个web.config(包括500个错误支持):
<configuration>
...
<system.web>
...
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Error/500.htm">
<error statusCode="404" redirect="~/Error/404.htm" />
<error statusCode="500" redirect="~/Error/500.htm" />
</customErrors>
...
</system.web>
...
<system.webServer>
...
<httpErrors errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="/Error/404.htm" responseMode="ExecuteURL" prefixLanguageFilePath="" />
<remove statusCode="500" />
<error statusCode="500" path="/Error/500.htm" responseMode="ExecuteURL" prefixLanguageFilePath="" />
</httpErrors>
...
</system.webServer>
...
</configuration>
Run Code Online (Sandbox Code Playgroud)
我还建议您使用.aspx页面,而不是.htm确保在响应标头中设置正确的状态代码.
<%@ Page Language="C#" %>
<% Response.StatusCode = 404; %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>404 Not Found</title>
</head>
<body>
404 Error
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8791 次 |
| 最近记录: |