ASP.NET 记录页面错误及自定义错误页
上一篇 /
下一篇 2008-02-14 14:49:24
/ 个人分类:IT技术
aspx.cs 上加记录错误
log到系统日志onerr方法
protected override void OnError(EventArgs e)
{
// At this point we have information about the error
HttpContext ctx = HttpContext.Current;
Exception exception = ctx.Server.GetLastError();
string errorInfo = "错误URL: " + ctx.Request.Url.ToString() + "\n源: " + exception.Source + "\n消息Message: " + exception.Message + "\n堆栈: " + exception.StackTrace;
//ctx.Response.Write(errorInfo);
// --------------------------------------------------
// To let the page finish running we clear the error
// --------------------------------------------------
//ctx.Server.ClearError();
//base.OnError(e);
string LogName = "MyWebError";
if (!System.Diagnostics.EventLog.SourceExists(LogName))
{
System.Diagnostics.EventLog.CreateEventSource(LogName, "App");
}
System.Diagnostics.EventLog el = new System.Diagnostics.EventLog();
el.Source = LogName;
el.WriteEntry(errorInfo, System.Diagnostics.EventLogEntryType.Error);
}
web.config 上修改友好错误页
<customErrors mode="On" defaultRedirect="MyErrorPage.aspx">
</customErrors>
删除事件
日志项
run regedit.exe
查找
\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog
删除对应的节点
导入论坛
收藏
分享给好友
推荐到圈子
管理
举报
TAG: