与内SecurityException异常引发异常只显示在ASP.NET MVC内部异常 [英] Throwing Exception with inner SecurityException only displays inner exception in ASP.NET MVC

查看:192
本文介绍了与内SecurityException异常引发异常只显示在ASP.NET MVC内部异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我下面的行添加到ASP.NET MVC操作方法

If I add the following line to an ASP.NET MVC action method

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

这是死亡的黄色屏幕上实际显示的错误是内在SecurityException异常,完全没有提及外的异常。

the error that is actually displayed on the yellow screen of death is the inner SecurityException with absolutely no mention of the outer exception.

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.

异常详细信息:System.Security.SecurityException:内

Exception Details: System.Security.SecurityException: inner

源错误:

的执行过程中生成了未处理的异常
  当前Web请求。有关的起源和位置信息
  除了可以使用异常堆栈跟踪下面来识别。

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.

堆栈跟踪:

[SecurityException异常:内]

[SecurityException: inner]

这是预期的行为?

这似乎并不重要外层的异常是什么类型。即使它是另一种SecurityException异常,是从来没有显示的消息。默认SecurityException异常错误信息是如此模糊,我想抓住它,并添加一些更具体的信息。如果我不包含原始SecurityException异常的的InnerException但我非常希望这样做这工作得很好。

It doesn't seem to matter what type the outer exception is. Even if it is another SecurityException, the message is never displayed. The default SecurityException error message is so vague that I want to catch it and add some more specific information. This works fine if I do not include the original SecurityException as the innerException but ideally I would like to do this.

推荐答案

这行为在ASP.NET核心起源,而不是在ASP.NET MVC。不幸的是,错误格式类是内部的,并且消耗类型不提供任何的扩展点,将允许一个来调整行为而不替换错误报告机制。解决方法是通过自定义错误页/视图,其中一个公开的信息,一个prefers替换默认页死亡的黄色画面。

This behaviour originates in the ASP.NET "core", not in ASP.NET MVC. Unfortunately, the error formatter classes are internal, and the consuming types do not provide any extension points that would allow one to tweak the behaviour without replacing the error reporting mechanism. The workaround is to replace the default "yellow screen of death" page by a custom error page/view in which one exposes the information that one prefers.

这正是我们应该平时做生产。根据你的情况,它只是意味着你会对调试备用版本,而不是使用ASP.NET提供的默认的。

This is exactly what one should usually be doing for production. In your case, it just means that you would have an alternate version for debug instead of using the ASP.NET-provided default.

这篇关于与内SecurityException异常引发异常只显示在ASP.NET MVC内部异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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