【发布时间】:2014-09-30 19:37:34
【问题描述】:
我在视图中设置了 /shared/error.cshtml 页面以显示更友好的错误消息。但是当用户遇到错误时它不会显示。
我的 web.config 文件有:
<system.web>
<customErrors mode="On" />
我的 global.asax.cs 有:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute ());
}
但我得到的错误信息仍然是基本的
`Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.
Details: To enable the details of this specific error message to be viewable on the local server machine, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, please set "mode" to "Off".`
我错过了什么?
【问题讨论】:
-
您到底想达到什么目的?如果您不指定自定义错误页面,那么将 CustomErrors 设置为 On 是没有意义的,对吧?基本上它说发生了错误并且显示自定义错误页面时出现错误...
-
我希望它转到共享布局中指定的error.cshtml。当您创建 MVC 应用程序时,它默认会执行此操作,但我们是从头开始构建的,所以我不知道如何
-
您应该有一个带有显示此视图的操作的 ErrorController。并且动作应该有以下注释:[HandleError(View = "Error", ExceptionType = typeof(Exception))]
-
您应该有一个带有显示此视图的操作的 ErrorController。并且动作应该有以下注释:
标签: c# asp.net-mvc asp.net-mvc-4