Where does in web.config go for MVC

2019-02-07 22:50发布

问题:

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.

回答1:

<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.