从一个新的MVC 3项目中,我修改了一个Index()动作来抛出异常。我希望呈现库存的Error.chhtml视图,因为我在web.config中设置了<customErrors mode="On" />
。相反,我从VS内部跑步时仍然得到“死亡的黄色屏幕”。
<system.web>
<customErrors mode="On" />
...
My HandleError属性是从global.asax.cs全局设置的。
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
根据默认项目设置,...未修改。我遇到了IIS Express和VS Dev Server。什么都没有导致自定义错误页面浮出水面。我错过了什么?
答案 0 :(得分:8)
我见过同样的问题,这是因为我添加了&lt; customErrors mode =“On”/&gt;到&lt; root&gt; \ Views \ Web.config,而不是&lt; root&gt; \ Web.config
答案 1 :(得分:1)
您使用的是哪种Web服务器? IIS7使用web.config的不同部分......这可能是你的问题。
看到这个: What is the difference between customErrors and httpErrors?
答案 2 :(得分:0)
请看一下有关MVC 3错误显示的文章。
答案 3 :(得分:0)
<system.web>
<customErrors mode="On" defaultRedirect="Error.html">
<error statusCode="403" redirect="/Error403" />
<error statusCode="404" redirect="/Error404" />
<error statusCode="500" redirect="/Error500" />
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL" >
<remove statusCode="403"/>
<remove statusCode="404"/>
<remove statusCode="500"/>
<error statusCode="403" responseMode="ExecuteURL" path="/Error403" />
<error statusCode="404" responseMode="ExecuteURL" path="/Error404" />
<error statusCode="500" responseMode="ExecuteURL" path="/Error500" />
</httpErrors>
</system.webServer>