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!
[HandleError]attribute on your HomeController when usingHandleErrorAttributeas a global filter.