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.
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.
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 .
<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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With