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
Asked
Active
Viewed 358 times
1
-
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 Answers
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:
- Create a new ASP.NET MVC 2 project using the default template
throw new Exception();
inside the Index action of theHomeController
.- Add in web.config:
<customErrors mode="On" />
- Hit Ctrl+F5 to run the project
- The
Error.aspx
page is shown.

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928
-
instead of 'throw new Exception();' try 'throw new HttpException(401,"wont work");' that wont work – Kuttan Sujith Mar 10 '11 at 04:41