/// <summary>
/// Application的错误响应。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_Error(Object sender, EventArgs e)
{
  System.Exception exp = Server.GetLastError();
  //保存或者记录异常日志,这里选择输出
  Response.Write(exp.Message);
}

解决方案 »

  1.   

    see
    HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using Visual C# .NET
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q306355
      

  2.   

    System.Diagnostics 命名空间提供了写入 Windows 事件日志的类。若要在页中使用此命名空间,必须先导入此命名空间,如下所示: 
    <%@ Import Namespace="System.Diagnostics"%>EventLog 类封装日志本身。它提供了检测或创建日志的静态方法,并且可被实例化以从代码写入日志项。下面的示例说明了 Global.asax 的 Application_Error 方法中的此功能。每当应用程序中发生未处理的异常时,包含错误信息和堆栈跟踪的项便写入应用程序日志。 
    void Application_Error(Object sender, EventArgs e) {     String Message = "\n\nURL:\n http://localhost/" + Request.Path
                                + "\n\nMESSAGE:\n " + Server.GetLastError().Message
                                + "\n\nSTACK TRACE:\n" + Server.GetLastError().StackTrace;     // Create event Log if it does not exist     String LogName = "Application";
         if (!EventLog.SourceExists(LogName)) {
            EventLog.CreateEventSource(LogName, LogName);
         }     // Insert into event log
         EventLog Log = new EventLog();
         Log.Source = LogName;
         Log.WriteEntry(Message, EventLogEntryType.Error);}