2

Okay, so I am trying to get my controller to go to the Error.cshtml under the Shared folder on error. I've got the filter configured at startup:

Global.asax

protected void Application_Start()
{
    ...
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    ...
}

FilterConfig.cs

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

HomeController.cs

[HandleError(View = "Error")] <---- I have the HandleError attribute
public class HomeController : Controller
{
    IDbConnection _connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);

    [Authorize]
    public ActionResult Index()
    {
        // get the users current events
        try
        {
            ViewBag.UserEvents = _connection.Query<MyEvents>("select ...)", new { });
        }
        catch (Exception ex)
        {
            throw new HttpException(500, ex.Message);
        }

        return View();
    }
    ...
}

And so when the Index method is throwing an exception because I didn't open the connection, it just gives me the default ASP.NET exception page. What did I miss here?

Thanks!

2
  • You don't need the HandleErrorAttribute when using HandleError as a global filter. Commented Oct 14, 2012 at 22:38
  • 2
    I mean, you don't need the [HandleError] attribute on your HomeController when using HandleErrorAttribute as a global filter. Commented Oct 14, 2012 at 22:46

1 Answer 1

7

Are you by any chance running this on your local machine? HandleError by default doesn't show errors on the local machine if you have customErrors set to Off or RemoteOnly. Set it to On.

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

1 Comment

Thank you, that is exactly what I needed, and I also pulled the attribute as you suggested!

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.