Mik*_*oud 2 c# error-handling asp.net-mvc-4
好的,所以我试图让我的控制器在错误Error.cshtml的Shared文件夹下去.我在启动时配置了过滤器:
protected void Application_Start()
{
...
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
...
}
Run Code Online (Sandbox Code Playgroud)
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
Run Code Online (Sandbox Code Playgroud)
[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();
}
...
}
Run Code Online (Sandbox Code Playgroud)
因此,当该Index方法抛出异常因为我没有打开连接时,它只是给了我默认的ASP.NET异常页面.我在这里想念的是什么?
谢谢!
您是否有机会在本地计算机上运行此操作?如果将customErrors设置为Off或RemoteOnly,则默认情况下HandleError不会在本地计算机上显示错误.将其设置为开.