好的,所以我试图让我的控制器在出错时转到文件夹Error.cshtml
下。Shared
我在启动时配置了过滤器:
全球.asax
protected void Application_Start()
{
...
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
...
}
过滤器配置文件
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
家庭控制器.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();
}
...
}
因此,当该Index
方法因为我没有打开连接而引发异常时,它只会给我默认的 ASP.NET 异常页面。我在这里错过了什么?
谢谢!