标签:object service pre nop obj ati context handler request
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();
}
标签:object service pre nop obj ati context handler request
原文地址:http://www.cnblogs.com/zhangrCsharp/p/7867876.html