我按照tutorial进行了操作,但我仍然收到了启用错误的ASP.NET屏幕,或者显示自定义错误页面。
我已经注册了HandleErrorAttribute并在web.config中添加了<customErrors mode="On" />
。该属性直接位于Controller类签名之前的行上。
我还缺少什么吗?
我按照你的建议从类中删除了属性,这就是结果。没有什么特别的事我想不到。
的web.config
</appSettings>
<system.web>
<customErrors mode="On" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
Global.asax中
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
错误*
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".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
答案 0 :(得分:1)
如果您希望查看自定义错误页面(您自己设计的页面),那么您需要实际创建页面并在customErrors元素中引用;
<customErrors defaultRedirect="GenericError.htm" mode="On" />
在上面的示例中,您将在Web应用程序中创建GernericError.htm页面。如果出现错误,将显示此信息。
如果您想查看有关抛出的实际异常的详细信息,则需要将模式设置为mode="Off"
或mode="RemoteOnly"
另外,请确保您在IIS中为您的应用程序运行正确版本的asp.net(即asp.net 4.0),否则您的web.config文件可能无法正确解析,从而导致此页面。
答案 1 :(得分:0)
Here is a conversation about Razor custom-views适合我和其他许多人。测试一下。也可能对你有帮助。