Search code examples
asp.net-mvcasp.net-mvc-4web-config

Where does <customErrors> in web.config go for MVC applications?


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.


Solution

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