Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Area Error Handling

I have a MVC project set up with 3 areas. In the main project I have error handling set up using custom errors in the web.config.

<customErrors mode="On" defaultRedirect="~/Error/HttpError">
     <error statusCode="404" redirect="~/Error/Http404" />     </customErrors>

This cause the site to redirect to a error controller in the root and then show the error view.

This works OK in the root site, however when I throw an exception in the home controller of one of the area sites it the message below.

Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.

Details: To enable the details of this specific error message to be viewable on the local server machine, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, please set "mode" to "Off".

Is it the case that error handling in the root site cannot be used in the area sites?

Thanks

John.

like image 840
user415394 Avatar asked Aug 09 '10 18:08

user415394


People also ask

How do you handle exceptions at controller level?

You can add extra ( @ExceptionHandler ) methods to any controller to specifically handle exceptions thrown by request handling ( @RequestMapping ) methods in the same controller. Such methods can: Handle exceptions without the @ResponseStatus annotation (typically predefined exceptions that you didn't write)

How does MVC handle application error in global ASAX?

Setting HandleError Attribute as a Global Filter Any unhandled exception that takes place within the boundary of the MVC application will now be handled by this global error handler. To test this global handler, comment out the [HandleError] attribute from the action or the controller and then run the application.


1 Answers

Does the area have it's own web.config that might be setting it's own error handling options? Can you put a breakpoint in Application_OnError to see if another error is occuring (eg. one loading the error page - eg. if you've turned off Buffering, it won't be able to do the redirect)?

You could also try adding the something like this to the main web.config to see if it it makes any difference:

<location path="nameOfArea">
  <system.web>
    <customErrors mode="On" defaultRedirect="~/Error/HttpError" />
  </system.web>    
</location>
like image 164
Danny Tuppeny Avatar answered Sep 21 '22 19:09

Danny Tuppeny