web.config中的在哪里用于MVC应用程序?

时间:2022-09-05 20:20:13

I'm attempting to implement custom error handling in my MVC 4 app. I'm not certain where in my web.config the <customErrors> is supposed to go, and the general information I need to include in it.

我正在尝试在我的MVC 4应用程序中实现自定义错误处理。我不确定我的web.config中的 应该去哪里,以及我需要包含在其中的一般信息。

1 个解决方案

#1


29  

<customErrors> goes inside <system.web>:

进入

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly">
            <error statusCode="500"
                   redirect="~/Error/InternalServer" />
            <error statusCode="404"
                   redirect="~/Error/NotFound" />
        </customErrors>
    </system.web>
</configuration>

Modify values of the redirect attributes according to your routes. You can also implement a catch-all redirect by adding a defaultRedirect attribute to the customErrors element. See this MSDN article for more information.

根据您的路由修改重定向属性的值。您还可以通过向customErrors元素添加defaultRedirect属性来实现catch-all重定向。有关更多信息,请参阅此MSDN文章。

#1


29  

<customErrors> goes inside <system.web>:

进入

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly">
            <error statusCode="500"
                   redirect="~/Error/InternalServer" />
            <error statusCode="404"
                   redirect="~/Error/NotFound" />
        </customErrors>
    </system.web>
</configuration>

Modify values of the redirect attributes according to your routes. You can also implement a catch-all redirect by adding a defaultRedirect attribute to the customErrors element. See this MSDN article for more information.

根据您的路由修改重定向属性的值。您还可以通过向customErrors元素添加defaultRedirect属性来实现catch-all重定向。有关更多信息,请参阅此MSDN文章。