“~”表示Web 应用程序根目录,“/”也是表示根目录,“../”表示当前目录的上一级目录,“./”表示当前目录
1 throw抛出异常 2 执行OnActionExecuted 方法 3执行 Global 中的 Application_Error 方法写入日志
global文件中写入 错误日志记录
protected void Application_Error(object sender,EventArgs e) { Exception lastError = Server.GetLastError(); if(lastError!=null) { string strExceptionMessage = string.Empty; //对HTTP 404做额外处理,其他错误全部当成500服务器错误 HttpException httpError = lastError as HttpException; if(httpError!=null) { //获取错误代码 int httpCode = httpError.GetHttpCode(); strExceptionMessage = httpError.Message; if(httpCode==400||httpCode==403||httpCode==404) { Response.StatusCode = httpCode; //跳转到指定的静态404信息页面 Response.WriteFile("~/404.html"); Server.ClearError(); return; } } log.Error(lastError.Message, lastError); Response.WriteFile("~/400.html"); #if DEBUG #else Server.ClearError(); #endif } }
原文地址:https://www.cnblogs.com/whl4835349/p/11606931.html
时间: 2024-10-07 00:13:28