我在我的应用程序中的异常处理非常相似,此解决方案: http://www.devcurry.com/2012/06/aspnet-mvc-handling-exceptions-and-404.html刷新页面3
有一个在我的应用程序一个讨厌的错误,这错误是可能的SQL死锁与另一个过程。这种情况很少发生(每天有1-2次请求因此而失败),但仍然发生。
如何自动刷新页面上的SQL死锁(并在获取请求时从最终用户以这种方式隐藏错误)?
我可以在Application_Error函数中做到吗?或者在HandleErrorAttribute中重写的OnException?
编辑:
我嘲笑了在BaseController一些代码,我创建了:
protected override void OnException(ExceptionContext filterContext)
{
Exception ex = filterContext.Exception;
SqlException sex = ex as SqlException;
if (sex != null && sex.Number == 1205)
{
Log.Error("Transaction deadlocked with the following exception:");
Log.Exception(sex);
//I need to write the logic that refreshes the page here.
}
else
{
Log.Error("Application error with the following exception:");
Log.Exception(ex);
}
base.OnException(filterContext);
}
我需要刷新部件的帮助。
所以写这刷新页面中onException的()函数是干的逻辑。你能帮我写出实际的逻辑吗? – SoonDead 2012-08-13 14:18:52
这高度依赖于您的应用程序。但是一种普遍的模式是在视图的视图模型中包含视图的路径,并将OnException重定向到该URL。这应该刷新视图。 – JTMon 2012-08-13 14:27:54
问题是当前的URL与我想要重定向的位置相同。但是Response.Redirect(Request.RawUrl)工作正常。 – SoonDead 2012-08-13 14:36:51