asp.net 异常处理
protected void Application_EndRequest(object sender, EventArgs e)
{
// 在应用程序关闭时运行的代码
HandlerError();
}
private void HandlerError()
{
if (HttpContext.Current != null)
{
if (string.IsNullOrEmpty(Request.QueryString["error"]))
{
var server = HttpContext.Current.Server;
var statusCode = HttpContext.Current.Response.StatusCode;
Exception ex = server.GetLastError();
if (ex != null || statusCode == 404 || statusCode == 500)
{
server.ClearError();
Response.StatusCode = 404;
Response.Redirect("//www.baidu.cn/nopage.html");
Response.End();
if (ex != null)
DependencyResolver.Current.GetService<ILog>().Log(ex);
}
}
}
}
protected void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
HandlerError();
}
这就是