ASP.NET MVC HandleError View Not Found
Asked Answered
O

4

2

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.

Ori answered 21/2, 2011 at 22:18 Comment(0)
Q
1

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. :)

Quarterphase answered 21/2, 2011 at 22:37 Comment(1)
This accomplishes the isolation of the error views that I am looking for. Thanks!Ori
M
3

AFAIK you cannot modify the location of those views. They should be in ~/Views/Shared. You could specify the name though per exception type:

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

where the EndSystemDownError view is located in ~/Views/Shared/EndSystemDownError.aspx.

Manolete answered 21/2, 2011 at 22:31 Comment(1)
I would say so too. Since there is a lot of convention, and this is not different case. If I were searching for Error view, I would look for it first in ~/Views/Shared folder :)Cumberland
Q
1

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. :)

Quarterphase answered 21/2, 2011 at 22:37 Comment(1)
This accomplishes the isolation of the error views that I am looking for. Thanks!Ori
C
0

did you try

[HandleError(Order = 1, ExceptionType = typeof(SocketsOfflineException), View="Error/EndSystemDownError")]
Cumberland answered 21/2, 2011 at 22:23 Comment(2)
I tried both Error/EndSystemDownError and /Error/EndSystemDownError to no avail.Ori
@David Marchelya, yeah, that's because it's not supported by the HandleError attribute.Manolete
C
0

Side note for Orchard module programming:

The HandleError attribute won't work in Orchard modules as Orchard implements a custom filter handling itself.

You need to implement a FilterProvider that overrides the OnResultExecuted() to catch exceptions thrown in a view.

See src\Orchard\Exceptions\Filters\UnhandledExceptionFilter.cs, it implements the common Orchard error page.

Coefficient answered 9/4, 2015 at 10:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.