Max*_*oro 64
这是为ASP.NET和非ASP.NET请求配置自定义404错误页面的方法:
<configuration>
<system.web>
<compilation targetFramework="4.0" />
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="http404.aspx" />
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404"/>
<error statusCode="404" path="/http404.aspx" responseMode="ExecuteURL"/>
</httpErrors>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
正如其他人已经指出的那样,你不应该使用HTTP重定向将用户发送到主页,这不仅会让用户感到困惑,也会混淆机器(例如搜索引擎).使用404状态代码而不是3xx代码非常重要.
您可以使用HTML上的元刷新来实现所需的功能:
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Not Found</title>
<meta http-equiv="refresh" content="5;url=/"/>
</head>
<body>
<h1>Not Found</h1>
<p>Redirecting to Home...</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
55326 次 |
| 最近记录: |