如果ASP.NET应用程序的CustomErrors设置为Off,有没有办法以编程
发布时间:2020-12-16 00:30:00 所属栏目:asp.Net 来源:网络整理
导读:我们通常在Global.asax中捕获未处理的异常,然后我们重定向到一个很好的友好错误页面。这对于Live环境很好,但是在我们的开发环境中,我们想检查CustomErrors是否为Off,如果是这样,只是抛出一个丑陋的错误。 有没有一个简单的方法来检查CustomErrors是否通
我们通常在Global.asax中捕获未处理的异常,然后我们重定向到一个很好的友好错误页面。这对于Live环境很好,但是在我们的开发环境中,我们想检查CustomErrors是否为Off,如果是这样,只是抛出一个丑陋的错误。
有没有一个简单的方法来检查CustomErrors是否通过代码关闭? 解决方法
是的,到
WebConfigurationManager :
System.Configuration.Configuration configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/"); System.Web.Configuration.CustomErrorsSection section = (CustomErrorsSection)configuration.GetSection("system.web/customErrors"); 一旦你有这个部分,你可以检查模式是开或关如下: CustomErrorsMode mode = section.Mode; if (mode == CustomErrorsMode.Off) { // Do something } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-core-mvc – 在ASP.NET Core中,通过将身份验证转发
- 第三方支付熟悉
- 从ASP.NET MVC Partial View中调用JavaScript
- asp.net-web-api – 无法加载文件或程序集’System.Web.Htt
- asp.net-mvc – MVC 4在局部视图中使用分页列表
- asp.net-mvc – 自动发现automapper配置
- 剃刀 – 我应该在哪里包含视图组件的脚本?
- asp.net – 从Owin WebApi2返回描述性401消息
- ASP.NET MVC 5中的Actionfilter注入
- asp.net-mvc – MVC 5 Bundle错误