您的位置:首页 > 编程语言 > ASP

ASP.NET 记录页面错误及自定义错误页

2008-12-27 21:16 701 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: