我在视图中设置了/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".`
我缺少什么?
答案 0 :(得分:0)
通过在
下添加以下行来激活Web.config中的自定义错误<system.web>:
<customErrors mode="On" defaultRedirect="/Error">
<error redirect="/Error/NotFound" statusCode="404"/>
<error redirect="/Error/InternalServerError" statusCode="500"/>
</customErrors>
注意:您可以设置mode =“Off”以禁用在开发或调试时可能有用的自定义错误。设置模式=“RemoteOnly”仅激活远程客户端的自定义错误
答案 1 :(得分:0)
你应该有一个ErrorController,其中包含一个显示错误视图的操作。该动作应该有以下注释:
[HandleError(View = "Error", ExceptionType = typeof(Exception))]
答案 2 :(得分:0)
想出来,当一个错误没有使用基本控制器时,一些动态内容没有被加载,因此错误处理引发了错误