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:

引用 删除   /   2008-04-29 17:07:15
引用 删除 Guest   /   2008-03-05 16:26:42
-3
 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-08-23  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 1490
  • 日志数: 27
  • 图片数: 3
  • 书签数: 7
  • 建立时间: 2007-01-08
  • 更新时间: 2008-02-27

RSS订阅

Open Toolbar