We can handle the errors in the MVC application by just enabling the custom errors tab in the web.config file.
<customErrors mode="On" defaultRedirect="Error">This will only handle the Internal Server Error Exceptions like HTTP Status Code 500 and won't handle the HTTP Status Code Exceptions like 404,405 etc for that we need to do the following.
<customErrors mode="On" defaultRedirect="Error">Here Error is the Controller Name and NotFound is the name of the Action Method after that we need to set the [HandleError] action filter on either the Controller or the Action Method as per our requirement.
<error statusCode="404" redirect="Error/NotFound" />
</customErrors>
No comments:
Post a Comment