在global里捕获黄页并写入异常日志库
可以在global文件中的application_error()中,记录用户操作中出现的异常日志
protected void Application_Error(Object sender, EventArgs e)
{
try
{
Exception exception = HttpContext.Current.Server.GetLastError();
// 如果有异常,则记录异常
if (exception != null)
{
exception = exception.GetBaseException();
log4net.ILog log = log4net.LogManager.GetLogger("ErrorLogFileAppender");
//先注释掉,用于开发调试之用
// 保存异常记录
System.Text.StringBuilder errorMessage = new System.Text.StringBuilder();
errorMessage.Append(Environment.NewLine);
errorMessage.Append("异常消息:");
errorMessage.Append(exception.Message);
errorMessage.Append(Environment.NewLine);
errorMessage.Append("异常用户:");
errorMessage.Append(Environment.NewLine);
errorMessage.Append("异常时间:");
errorMessage.Append(System.DateTime.Now.ToString());
errorMessage.Append(Environment.NewLine);
errorMessage.Append("异常位置:");
errorMessage.Append(Environment.NewLine);
errorMessage.Append(exception.StackTrace);
errorMessage.Append(Environment.NewLine);
![](/Images/OutliningIndicators/InBlock.gif)
OperationLogBL logBl = new OperationLogBL();
OperationLogData data = new OperationLogData();
data.OperateDate = DateTime.Now;
data.OperatorId = CurrentUser.Info.UserID;
data.OperatorName = CurrentUser.Info.UserName;
data.OperatorEnName = CurrentUser.Info.UserNameEn;
data.TypeNo = (int)Model.LogType.错误日志;
data.Remark = errorMessage.ToString();
data.ModifiedId = exception.Source;
data.ModifiedItem = Request.UserHostAddress;
data.OldValue = Request.RawUrl.ToString();
logBl.Add(data);
} // end if (exception != null)
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
// 跳转至 [异常提示] 页面
if (ConfigurationSettings.AppSettings["EnableErrorPage"].ToLower() == "true")
{
string url = ConfigurationSettings.AppSettings["NoRightRedirect"];
Response.Redirect(url);
}
}
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="/genericerror.htm"> <error statusCode="500" redirect="/error/callsupport.htm"/> <error statusCode="404" redirect="/error/notfound.aspx"/>
<error statusCode="403" redirect="/error/noaccess.aspx"/> </customErrors> </system.web></configuration>mode
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
net的错误机制处理:
。<customErrors> 配置节支持内部 <error> 标记,该标记将 HTTP 状态代码与自定义错误页关联。例如:
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
mode:指示自定义错误是启用、禁用还是只向远程计算机显示。值:On、Off、RemoteOnly(默认值)。
愿一路奔跑不退缩,到目前一直从事.Net的B/S,C/S企业应用研发