1

I am doing MVC 2 I have given HandleError attribute to all of my controller class. I have In my web.config I also have Error.aspx in my shared folder of views. Still on an exception in controller, The Error.aspx is not rendered

Kuttan Sujith
  • 7,889
  • 18
  • 64
  • 95
  • Check out [this post](http://stackoverflow.com/questions/1171035/asp-net-mvc-custom-error-handling-application-error-global-asax). – Bala R Mar 06 '11 at 19:39

2 Answers2

0

There are a lot of questions about this on StackOverflow because this is a tricky one with a lot of gotchas if you're not careful. From the sound of it, you need to set the HTTP Response to OK, otherwise the server will still render a generic 500 Error page because it still thinks the exception was not handled properly.

To do this, in your error view, add the following code:

@{ Response.StatusCode = (int)HttpStatusCode.OK; }

Let us know if this works for you!

Edit: You also need to make sure that you have <customErrors mode="On"/> in the <System.Web> section of the web.config file at the root of your website.

Robert Becker
  • 143
  • 1
  • 1
  • 6
0

Steps:

  1. Create a new ASP.NET MVC 2 project using the default template
  2. throw new Exception(); inside the Index action of the HomeController.
  3. Add in web.config: <customErrors mode="On" />
  4. Hit Ctrl+F5 to run the project
  5. The Error.aspx page is shown.
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928