I’ve read a dozen similar questions on StackOverflow, but I can’t seem to grasp this. With regards to the custom errors node in the web.config and the HandleErrorAttribute, how does the Error.cshtml ever get called? Ultimately the answer to this question may be the answer to one of those several questions already out there regarding ASP.NET MVC error handling. But, fact of the matter is, I don’t know which one.
Share
Inside your Global.asax you have the following method:
This registers the HandleErrorAttribute as global action filter. This means that this handler is automatically applied to all controller actions. Now let’s take a look at how this attribute is implemented by looking at the source code:
The source code contains comments and is more than self explanatory. The first thing it checks is whether you have enabled custom errors in your web.config (i.e.
<customErrors mode="On">). If you haven’t it does nothing => YSOD. If you have enabled custom errors then it renders the Error view passing it a model containing the exception stacktrace and other useful information.