1

I have created a new MVC Application in VS2010 straight out the box. In the Home Controller I have ther following:

    [HandleError(View = "Error")]
    public ActionResult Index()
    {


        int num1 = 0;
        int num2 = 5;

        int result = num2 / num1;

        return View();

    }

This creates an error and a debug pop up and then if I continue a yellow screen. I cannot get it to redirect to the Error.aspx page. I have the web.config like this:

 <customErrors mode="On" defaultRedirect="~/Error.aspx">
 </customErrors>

but it will not redirect to the correct error page despite being a brand new project. How do I configure this to work please????

thanks

1
  • 1
    Post what the error message is on the yellow screen Commented Jul 19, 2010 at 19:04

3 Answers 3

1

This is discussed in the MVC overview tutorials. The behaviour of IIS errors is dependent on your version of IIS.

Using ASP.NET MVC with Different Versions of IIS (C#)

Sign up to request clarification or add additional context in comments.

3 Comments

I cannot see anything about error handling from that link - a good resource though. I have IIS 7.0
Oops! Wrong answer. You might try this stackoverflow.com/questions/619895/…
Thanks great link. I just create a new mvc project and threw an error in the Index action of the home controller and it worked. I don't understand why it didnt work the first time and I never will. I still get the debugger kicking in though. What mode do I need to be in to stop this from happening? and how do I put it in that mode??
1

If I try to replicate this I get redirected to the default error view within the Shared view folder - it looks like MVC overrides any setting made to the defaultRedirect attribute in the web.config.

In your web.config you are trying to redirect to a physical aspx page. The HandleError attribute on your action will attempt to find a view named Error first within your specific view folder, moving on to the shared view folder. Just pick one or the other and you should be fine.

Comments

0

Try this blog post: http://msnetprogrammer.net/blog/post/HandleError-attribute-%28MVC%29.aspx

Also the default View name is Error so you technically can just have [HandleError]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.