在web.config中:
<customErrors mode="RemoteOnly">
<error statusCode="404" redirect="/error/404Page.aspx"/>
<error statusCode="403" redirect="/error/403page.aspx"/>
</customErrors>在Global.asax中:
protected void Application_Error(Object sender, EventArgs e)
{
Exception LastError = Server.GetLastError();
String ErrMessage = LastError.ToString(); String LogName = "MyLog";
String Message = "Url " + Request.Path + " Error: " + ErrMessage; // Create Event Log if It Doesn't Exist if (!EventLog.SourceExists(LogName))//错误发生处,用户代码未处理SecurityException,不可访问的日 志:Security
{
EventLog.CreateEventSource(LogName, LogName);
}
EventLog Log = new EventLog();
Log.Source = LogName;
//These are the five options that will display a different icon.
Log.WriteEntry(Message, EventLogEntryType.Information, 1);
Log.WriteEntry(Message, EventLogEntryType.Error, 2);
Log.WriteEntry(Message, EventLogEntryType.Warning, 3);
Log.WriteEntry(Message, EventLogEntryType.SuccessAudit, 4);
Log.WriteEntry(Message, EventLogEntryType.FailureAudit, 5); }
请各位大神帮忙,谢谢!!
<customErrors mode="RemoteOnly">
<error statusCode="404" redirect="/error/404Page.aspx"/>
<error statusCode="403" redirect="/error/403page.aspx"/>
</customErrors>在Global.asax中:
protected void Application_Error(Object sender, EventArgs e)
{
Exception LastError = Server.GetLastError();
String ErrMessage = LastError.ToString(); String LogName = "MyLog";
String Message = "Url " + Request.Path + " Error: " + ErrMessage; // Create Event Log if It Doesn't Exist if (!EventLog.SourceExists(LogName))//错误发生处,用户代码未处理SecurityException,不可访问的日 志:Security
{
EventLog.CreateEventSource(LogName, LogName);
}
EventLog Log = new EventLog();
Log.Source = LogName;
//These are the five options that will display a different icon.
Log.WriteEntry(Message, EventLogEntryType.Information, 1);
Log.WriteEntry(Message, EventLogEntryType.Error, 2);
Log.WriteEntry(Message, EventLogEntryType.Warning, 3);
Log.WriteEntry(Message, EventLogEntryType.SuccessAudit, 4);
Log.WriteEntry(Message, EventLogEntryType.FailureAudit, 5); }
请各位大神帮忙,谢谢!!
SecurityException是安全性问题,asp.net是匿名账户运行,没有权限写日志