2009-09-30 60 views
2

在過去的兩週裏,我遇到了一個我無法弄清楚的情況,也許你們已經通過了相同的問題或耳朵/瞭解它並能幫助我。什麼能導致Application_Error不被調用?

我有我的機器和其他機器上運行良好的ASP.NET項目,每次我試圖錘鍊查詢字符串我得到的是被投擲由System.Exception的

問題是一個錯誤的時間,在這個特定的機器中(巫婆在荷蘭),Application_Error永遠不會捕獲異常,它會將異常消息保存到日誌中(因爲在我的應用程序中應該這樣做),但它不會「中斷」Web應用程序......它只是繼續!

如何以及如何使這成爲可能?


爲例着想,這是我的網頁(HttpCache canot調用這個樣子,但我使用的Web.HttpCache對象僅僅是點)

if(Request.QueryString["user"] != HttpCache["MYAPP-user"]) { 
    myApp.DebugWrite("User was tempered."); 
    throw System.Exception("User was tempered."); 
} 

和在Global.asax的

... 

void Application_Error(object sender, EventArgs e) 
{ 
    // Code that runs when an unhandled error occurs 
    if (Server.GetLastError() != null) 
    { 
     Exception objErr = Server.GetLastError().GetBaseException(); 
     String url = Request.Url.ToString(); 
     String msg = objErr.Message; 
     String trc = objErr.StackTrace.ToString(); 


     Response.Clear(); 

     StringBuilder html = new StringBuilder(); 
     // fill up html with html code in order to present a nice message 
     Response.Write(html.ToString()); 

     Server.ClearError(); 
     Response.Flush(); 
     Response.End(); 
    } 
} 

... 

在我的測試機器上,我總是得到帶有錯誤信息的html,以及日誌中的消息...在這臺特定的機器上,我只看到日誌中的錯誤,但應用程序繼續 !!!

的web.config是完全一樣在所有的機器和此Web應用程序的.NET 2.0

運行時,它可能是什麼?

回答

-2

註釋掉響應,並在你的代碼Server.ClearError()部分:

//Response.Clear(); 

       StringBuilder html = new StringBuilder(); 
       // fill up html with html code in order to present a nice message 
       Response.Write(html.ToString()); 

       //Server.ClearError(); 
       //Response.Flush(); 
       //Response.End(); 
+0

-1不知道你是否notest,但異常從來沒有得到的到的Application_Error – balexandre 2009-10-02 11:49:00

+0

你應該只是做了評論而不是-1。 :( – azamsharp 2009-10-02 18:14:55

相關問題