Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom errors override in ASP.NET MVC area

I would like to have custom error pages unique to an MVC area. Unfortunately, it appears that the Web.config override system doesn't take the MVC folder structure into account. If I want to override an area called "mobile", I have to create a root project folder (in with Views and Controllers) named "mobile" and put the Web.config in there with the new customErrors element.

Is there some better way to do this so that I don't have to create a root folder for any overrides?

like image 918
patridge Avatar asked Aug 03 '10 17:08

patridge


People also ask

How to display custom Error page in ASP net?

Steps for Custom Error PageAdd Web Form for custom error page. Set <customErrors> setting in Web. Config file of the application. Pass defaultRedirect and mode attributes in <customErrors>.


1 Answers

I've been looking for exactly the same thing. One slight change that I do is to use a location element within the main web.config. It's a matter of preference I suppose, but it keeps you from having to create a separate folder and file within your solution. I'd love to know a better way though.

<system.web>
  <customErrors mode="On" defaultRedirect="error" />
</system.web>
.
.
.
<location path="areaName">
  <system.web>
    <customErrors mode="On" defaultRedirect="/areaName/error" />
  </system.web>    
</location>
like image 109
Zach Parrish Avatar answered Sep 26 '22 14:09

Zach Parrish