asp.net-mvchandleerror

ASP.NET MVC HandleError View Not Found


I'm trying to implement exception handling in ASP.NET MVC3 using the HandleError attribute.

The code that I'm using looks like this:

[HandleError(Order = 1, ExceptionType = typeof(SocketsOfflineException), View="EndSystemDownError")]

This works as expected when the EndSystemDownError view is located in the "Shared" folder. However, I have a number of Error views, and I want to separate them out into a folder specifically for Errors, called "Error".

So I pull the EndSystemDownError view out of the shared folder and into an "Error" subfolder in the Views folder. I then update the View property to ~/Views/Error/EndSystemDownError. This however results in an exception stating that the view was not found. I tried /Views/Error/EndSystemDownError as well, with the same results.

I have tried adding an ErrorController with an EndSystemDownError action, both as a troubleshooting measure, and because I would like to add some controller functionality to the view. This has no effect.

I can't seem to figure out what I'm doing wrong. Perhaps this is a bug in MVC, or maybe it doesn't support error views outside of the Shared folder, which would be disappointing.


Solution

  • If you put your errors subfolder inside of the shared folder, you can refer to it by Errors/whatevererror.aspx and it should be fine.

    I do this frequently. After all they are shared views. :)