向网站添加自定义错误页面
我有一个使用 web.config 的网站。我尝试添加以下代码:
<customErrors mode="On" defaultRedirect="error.htm">
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
但它似乎不起作用。错误仍然出现。我可能把它放在错误的地方吗?
样本:
<authentication mode="Forms">
<!-- Assign login url to LOGINSTATUS control -->
<!-- log user out after 15 minutes of inactivity -->
<forms loginUrl="~/Tilton/Login/Login.aspx" timeout="15"/>
</authentication>
<customErrors mode="On" defaultRedirect="error.htm">
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
I have a website that makes use of a web.config. I tried adding in the following code:
<customErrors mode="On" defaultRedirect="error.htm">
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
But it doesn't seem to work. Errors still show up. Could I be putting it in the wrong place?
Sample:
<authentication mode="Forms">
<!-- Assign login url to LOGINSTATUS control -->
<!-- log user out after 15 minutes of inactivity -->
<forms loginUrl="~/Tilton/Login/Login.aspx" timeout="15"/>
</authentication>
<customErrors mode="On" defaultRedirect="error.htm">
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ASP.NET 错误处理程序仅适用于 ASP.NET 引擎应该处理的资源(如果存在)。例如,您的处理程序应该适用于 nonexist.aspx,但不适用于 foo.bar,因为 .bar 未映射到 ASP.NET。这是你的问题吗?
The ASP.NET error handler only works for resources that would have been handled by the ASP.NET engine should they exist. Example, your handler should work for nonexist.aspx, but won't work for foo.bar because .bar is not mapped to ASP.NET. Is this your problem?
您可以考虑在 IIS 本身中设置自定义 404 错误页面。在 IIS 7 中,每个网站都有一个“错误页面”配置部分。
You could look at setting a custom 404 error page within IIS itself. In IIS 7 there's a 'error pages' configuration section for each website.