MVC 3 custom errors not displaying

From a new MVC 3 project, I changed the Index () action to throw an exception. I expect the Error.chhtml view to display because I set <customErrors mode="On" /> to web.config. Instead, I still get a "yellow screen of death" while working from VS.

 <system.web> <customErrors mode="On" /> ... 

The My HandleError attribute is set globally from global.asax.cs.

  public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } 

... unmodified, by default for the project. I worked against IIS express and VS Dev Server. Nothing results in a user error page. What am I missing?

+6
source share
4 answers

I saw the same problem due to which I added <customErrors mode = "On" /> to <root> \ Views \ Web.config rather than <root> \ Web.config

+8
source

Which web server are you using? IIS7 uses a different web.config section ... this may be your problem.

See this: What is the difference between customErrors and httpErrors?

+1
source

Please take a look at this MVC 3 error mapping article.

Error Handling and User Errors and MVC3

0
source
  <system.web> <customErrors mode="On" defaultRedirect="Error.html"> <error statusCode="403" redirect="/Error403" /> <error statusCode="404" redirect="/Error404" /> <error statusCode="500" redirect="/Error500" /> </customErrors> </system.web> <system.webServer> <httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL" > <remove statusCode="403"/> <remove statusCode="404"/> <remove statusCode="500"/> <error statusCode="403" responseMode="ExecuteURL" path="/Error403" /> <error statusCode="404" responseMode="ExecuteURL" path="/Error404" /> <error statusCode="500" responseMode="ExecuteURL" path="/Error500" /> </httpErrors> </system.webServer> 
0
source

Source: https://habr.com/ru/post/888791/


All Articles