ASP.NET的customErrors与模式=仅限远程和Global.asax中处理异常 [英] ASP.NET customErrors with mode=remoteOnly and global.asax handling exceptions

查看:120
本文介绍了ASP.NET的customErrors与模式=仅限远程和Global.asax中处理异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Web配置文件中设置自定义错误如下:

I have custom errors set in the web config file as follows:

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

罚款和花花公子...我喜欢该模式=仅限远程有利于发展...

Fine and dandy... I like that mode="RemoteOnly" facilitates development...

有关未处理的异常,我在Global.asax的:

For unhandled exceptions, I have in global.asax:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    Response.Redirect("GenericError.aspx")
End Sub

然而,未处理的异常是要在一般性的错误页面,而不是开发商pferred死亡$ P $的翔实黄屏。我可以注释掉在Global.asax中重定向,但我需要记住改变它的生产环境。有没有一种方法我可以的Application_Error检查是否我远程与否来决定是否重定向?

However, unhandled exceptions are going to the generic error page instead of the informative yellow screen of death preferred by developers. I can comment out the redirect in global.asax, but then I need to remember to change it for the production environment. Is there a way I can check in Application_Error whether I am remote or not to determine whether to redirect?

推荐答案

您不要在Global.asax需要的Response.Redirect 。它复制了&LT的行为;&的customErrors GT; 标记。仅限远程将会给最终用户的自定义错误消息和当地的USR标准asp.net错误页面。如果你的开发人员使用本地Web服务器的发展,你在一个兼得。

You do not need the Response.Redirect in the Global.asax. It duplicates the behaviour of the <customErrors> tag. RemoteOnly will give end users the custom error message and local usrs the standard asp.net error page. If your developers use a local web server for development you have both in one.

另一种方法是将&LT;的customErrors&GT; 关闭开发服务器上,并将其设置为在生产环境中。有在web.config中通常很多项目需要改变,因此不再是一个困难的。

Another approach is to set the <customErrors> to Off on development servers and set it to On in the production environment. There are usually many items in the web.config that need changing so it is no more of a hardship.

这篇关于ASP.NET的customErrors与模式=仅限远程和Global.asax中处理异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆