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>
{
// 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>
相关文章推荐
- ASP.NET全局错误处理和异常日志记录以及IIS配置自定义错误页面
- Asp.Net自定义错误页面
- ASP.NET自定义错误页面(转)
- 基于 ASP.NET Core 2.1 的 Razor Class Library 实现自定义错误页面的公用类库
- asp.net中自定义错误处理页面
- ASP.NET自定义错误页面(转)
- 在ASP.NET MVC 如何在Response.StatusCode = 404的同时,显示友好的自定义错误页面
- ASP.NET Core中显示自定义错误页面-增强版
- asp.net中创建自定义的错误处理页面
- ASP.NET自定义错误页面
- ASP.NET自定义错误页面
- ASP.NET自定义错误页面
- asp.net自定义错误页面
- ASP.NET自定义的错误页面
- ASP.NET自定义错误页面
- ASP.NET自定义错误页面
- ASP.NET自定义错误处理页面的添加
- ASP.NET自定义错误处理页面的添加
- ASP.NET自定义错误页面
- ASP.NET MVC 3 中,自定义全局的错误处理页面