加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

使用内部SecurityException抛出异常仅在ASP.NET MVC中显示内部异

发布时间:2020-12-16 03:50:30 所属栏目:asp.Net 来源:网络整理
导读:如果我将以下行添加到ASP.NET MVC操作方法 throw new Exception("outer",new SecurityException("inner")); 实际显示在死亡黄色屏幕上的错误是内部SecurityException,绝对没有提到外部异常. SecurityException Description: The application attempted to pe
如果我将以下行添加到ASP.NET MVC操作方法

throw new Exception("outer",new SecurityException("inner"));

实际显示在死亡黄色屏幕上的错误是内部SecurityException,绝对没有提到外部异常.

SecurityException

Description: The application attempted to perform an operation not
allowed by the security policy. To grant this application the
required permission please contact your system administrator or change
the application’s trust level in the configuration file.

Exception Details: System.Security.SecurityException: inner

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

Stack Trace:

[SecurityException: inner]

这是预期的行为吗?

外部异常的类型似乎并不重要.即使它是另一个SecurityException,也不会显示该消息.默认的SecurityException错误消息是如此模糊,我想捕获它并添加一些更具体的信息.如果我不包含原始的SecurityException作为innerException,但是理想情况下我想这样做,这样可以正常工作.

解决方法

此行为源自ASP.NET“核心”,而不是ASP.NET MVC.不幸的是,错误格式化程序类是内部的,并且消费类型不提供任何扩展点,允许用户调整行为而不替换错误报告机制.解决方法是通过自定义错误页面/视图替换默认的“黄色死亡屏幕”页面,其中一个公开了一个人喜欢的信息.

这正是人们通常应该为生产做的事情.在您的情况下,它只是意味着您将有一个备用版本用于调试,而不是使用ASP.NET提供的默认值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读