gpt4 book ai didi

ASP.NET customErrors with mode=remoteOnly 和 global.asax 处理异常

转载 作者:行者123 更新时间:2023-12-04 15:27:40 25 4
gpt4 key购买 nike

我在 web 配置文件中设置了自定义错误,如下所示:

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

很好,花花公子......我喜欢那种模式=“RemoteOnly”有利于开发......

对于未处理的异常,我在 global.asax 中有:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect("GenericError.aspx")
End Sub

但是,未处理的异常将进入通用错误页面,而不是开发人员首选的信息性黄色死亡屏幕。我可以在 global.asax 中注释掉重定向,但是我需要记住为生产环境更改它。有没有办法可以检查 Application_Error 是否远程确定是否重定向?

最佳答案

您不需要 Response.Redirect在 Global.asax 中。它复制了 <customErrors> 的行为标签。 RemoteOnly 将为最终用户提供自定义错误消息,并为本地用户提供标准的 asp.net 错误页面。如果您的开发人员使用本地 Web 服务器进行开发,则两者合二为一。

另一种方法是设置<customErrors>Off在开发服务器上并将其设置为 On在生产环境中。 web.config 中通常有许多项目需要更改,因此不再是困难。

关于ASP.NET customErrors with mode=remoteOnly 和 global.asax 处理异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3283008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com