Sounds like you don't have the error attribute in your global filters. In an MVC 4 project you should be able to search for the class FilterConfig
that was generated for you:
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
}
Update:
The HandleErrorAttribute
global filter is for errors that occur in the MVC pipeline, such as errors in your controller as you mention.
The customErrors
element in the web.config
is for everything else. The HandleErrorAttribute
will not honor the value you put in the defaultRedirect
attribute of customErrors
.
The HandleError
filter will look for a shared view which you should have in your generated project shared\Error.cshtml
. You can point it to a different view by setting a property on the attribute.
For example, let's say we create a new view under Shared\Errors\CustomError.cshtml
, then you could register the filter like this:
filters.Add(new HandleErrorAttribute(){View = "Errors/CustomError"});