添加 web.config 键,以便在出现未处理的异常时始终重定向

发布于 2024-09-28 01:38:08 字数 85 浏览 1 评论 0原文

我曾经看到可以做一些事情,比如在 web.config 文件中添加一个键,以在每次发现未处理的异常时重定向到默认错误页面。

是否可以?如何?

I once saw that was possible to do something like adding a key in the web.config file to redirect to a default error page everytime a unhandled exception is found.

Is it possible? how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一个人练习一个人 2024-10-05 01:38:08

是的,web.config 的 customErrors 部分。

<customErrors defaultRedirect="~/GenericError.aspx" mode="On" />

这会将您的用户在遇到错误时重定向到 defaultRedirect (URL)。

您还可以根据 HTTP 响应代码指定它们的去向。

<customErrors defaultRedirect="~/GenericError.aspx" mode="On">
    <error statusCode="500" redirect="~/Error.aspx"/>
    <error statusCode="404" redirect="~/NotFound.aspx"/>
</customErrors>

这是文档。

Yes the customErrors section of the web.config.

<customErrors defaultRedirect="~/GenericError.aspx" mode="On" />

This will redirect your users to what defaultRedirect (URL) when they encounter an error.

You can also specify where they go based on the HTTP response code

<customErrors defaultRedirect="~/GenericError.aspx" mode="On">
    <error statusCode="500" redirect="~/Error.aspx"/>
    <error statusCode="404" redirect="~/NotFound.aspx"/>
</customErrors>

Here is the documentation.

温折酒 2024-10-05 01:38:08

CustomErrors 部分添加到您的 web.config 中。

<customErrors defaultRedirect="ErrorPage.aspx" mode="RemoteOnly" />

Add a CustomErrors section to your web.config.

<customErrors defaultRedirect="ErrorPage.aspx" mode="RemoteOnly" />
情何以堪。 2024-10-05 01:38:08
<customErrors defaultRedirect="~/serverErrorPage.aspx" mode="On" redirectMode="ResponseRewrite"/>

它不适合在 .NET3.5 Service Pack 1 之前的实际使用,因为在那之前,redirectMode 属性不存在,并且它始终使用默认值 "ResponseRedirect" 进行操作,该值将重定向到错误页面而不是直接显示;因此,它不会给出错误响应,而是“成功”重定向到另一个页面,然后将返回错误!

<customErrors defaultRedirect="~/serverErrorPage.aspx" mode="On" redirectMode="ResponseRewrite"/>

It's not suitable for real use prior to .NET3.5 service pack 1, as until then the redirectMode attribute wasn't there and it would always act with the default value "ResponseRedirect" which would redirect to the error page instead of showing it directly; so instead of giving an error response it would "successfully" redirect to another page, and then that would return the error!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文