MVC 3自定义错误未显示

时间:2022-10-13 17:01:35

From a fresh MVC 3 Project, I've modified an Index() action to throw an exception. I expect the stock Error.chhtml view to be rendered, because I've set <customErrors mode="On" /> in the web.config. Instead, I still get the "yellow screen of death" while running from within VS.

从一个新的MVC 3项目,我已经修改了一个Index()动作来抛出异常。我希望渲染库存的Error.chhtml视图,因为我在web.config中设置了 。相反,我从VS内部跑步时仍然得到了“死亡的黄色屏幕”。

<system.web>
  <customErrors mode="On" />
  ...

My HandleError attribute is set globally from the global.asax.cs.

My HandleError属性是从global.asax.cs全局设置的。

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
    }

...unmodified, per the default project setup. I've run against both IIS express and VS Dev Server. Nothing causes the custom error page to surface. What am I missing?

...根据默认项目设置,未修改。我遇到了IIS Express和VS Dev Server。什么都没有导致自定义错误页面浮出水面。我错过了什么?

4 个解决方案

#1


8  

I have seen the same problem, which is due to that I added <customErrors mode="On" /> to <root>\Views\Web.config, instead of <root>\Web.config

我看到了同样的问题,这是因为我将 添加到 \ _ Views / Web.config,而不是 \ Web.config

#2


1  

What web server are you using? IIS7 uses a different section of the web.config...that may be your problem.

你使用什么Web服务器? IIS7使用web.config的不同部分......这可能是你的问题。

See this: What is the difference between customErrors and httpErrors?

请参阅:customErrors和httpErrors有什么区别?

#3


0  

Please take a look at this article about MVC 3 Error Display.

请看一下有关MVC 3错误显示的这篇文章。

Error Handling and CustomErrors and MVC3

错误处理和CustomErrors以及MVC3

#4


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>

#1


8  

I have seen the same problem, which is due to that I added <customErrors mode="On" /> to <root>\Views\Web.config, instead of <root>\Web.config

我看到了同样的问题,这是因为我将 添加到 \ _ Views / Web.config,而不是 \ Web.config

#2


1  

What web server are you using? IIS7 uses a different section of the web.config...that may be your problem.

你使用什么Web服务器? IIS7使用web.config的不同部分......这可能是你的问题。

See this: What is the difference between customErrors and httpErrors?

请参阅:customErrors和httpErrors有什么区别?

#3


0  

Please take a look at this article about MVC 3 Error Display.

请看一下有关MVC 3错误显示的这篇文章。

Error Handling and CustomErrors and MVC3

错误处理和CustomErrors以及MVC3

#4


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>