Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 840
Hosea146 Avatar asked Apr 27 '13 10:04

Hosea146


People also ask

What is customErrors tag within a web config?

This <customErrors> tag should then have its "mode" attribute set to "Off". When customErrors is set to On or RemoteOnly, you need to specify the defaultRedirect attribute. This attribute contains the error page to which the user will be redirected.

Where is web config file in MVC?

This file is typically found in the C:\WINDOWS\Microsoft.NET\Framework\v2. 0.50727\CONFIG directory. The Machine. config file contains settings for all sites running on the machine provided another .


2 Answers

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

like image 189
Ant P Avatar answered Oct 13 '22 01:10

Ant P


In web.config file under root directory

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

Create a shared folder under view folder, and create a view under shared folder for showing Error message

in action use that [HandleError] like

[HandleError]
    public ActionResult Errors()
    {
        throw new Exception();
    }
like image 38
Md Jahangir Alam Avatar answered Oct 13 '22 00:10

Md Jahangir Alam