protected void Application_Error(Object sender, EventArgs e)
{
Exception lastError = Server.GetLastError();
if (lastError != null)
{
//异常信息
string strExceptionMessage = string.Empty;
try
{
string url = Request.Url.OriginalString;
string[] ignorFiles = { ".css", ".js", ".jpg", ".jpeg", ".png", ".rar", ".exe", ".bmp", ".png", ".doc", ".docx", ".xml", ".xsd", ".xls", ".xlsx", ".ppt", ".pptx" };
//如果是忽略文件,不写入访问日志
if (ignorFiles.Any(m => url.EndsWith(m, StringComparison.OrdinalIgnoreCase)))
{
return;
}
}
catch { }
//对HTTP 404做额外处理,其他错误全部当成500服务器错误
HttpException httpError = lastError as HttpException;
//if (httpError != null)
//{
// //获取错误代码
// int httpCode = httpError.GetHttpCode();
// strExceptionMessage = httpError.Message;
// if (httpCode == 400 || httpCode == 404)
// {
// Response.StatusCode = 404;
// Server.ClearError();
// //Response.Redirect("~/Web/Error?title=" + Server.UrlEncode("404") + "&desc=" + Server.UrlEncode("请求的资源不存在!"));
// Response.Redirect("~/Base/Error?note=无效的URL路径!");
// return;
// }
//}
strExceptionMessage = lastError.Message;
/*-----------------------------------------------------
* 此处代码可根据需求进行日志记录,或者处理其他业务流程
* ---------------------------------------------------*/
/*
* 跳转到指定的http 500错误信息页面
* 跳转到静态页面一定要用Response.WriteFile方法