2013-06-27 18 views
1

與具有大量的UpdatePanel一些舊代碼工作。我們正在經歷一些地方對回發的UpdatePanel的超時(超過默認的90秒限制)的問題,我想知道什麼時候發生這種情況。超時錯誤跳過Appliation_Error - 我該如何抓住他們?

目前,我們正在登錄的Global.asax.cs ::的Application_Error所有未處理的異常。如果我在更新面板上手動拋出一個回發中的錯誤,就可以很好地捕獲這個錯誤。如果我在一個Thread.sleep代碼(100 * 1000)回落,我會不看到中的Application_Error什麼,但在客戶端上我會看到:

Uncaught Sys.WebForms.PageRequestManagerServerErrorException: 
    Sys.WebForms.PageRequestManagerServerErrorException: 
     An unknown error occurred while processing the request on the server. 
     The status code returned from the server was: 500 

從我可以告訴,這是服務器層拋出錯誤,而不是應用程序本身,所以我們永遠不會看到任何命中Application_Error。那是對的嗎?

另外,除了在客戶端注意到這個錯誤之外,是否還有任何實際捕獲/記錄此錯誤的選項,然後再執行另一個POST操作來記錄它?

回答

0

你,我知道有兩種方法:

Server-side: 
protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e) 
{ 
    ScriptManager1.AsyncPostBackErrorMessage = "An error occurred during the request: " + e.Exception.Message; 
} 

Client-side: 
<script type="text/javascript"> 
    // Subscribe to the end request event of the update panel 
    function pageLoad() { 
     Sys.WebForms.PageRequestManager.getInstance().add_endRequest(onEndRequest); 
    } 

    // You can of course have this emit the error information to whatever control you want, I made up the Label1 object for demonstration purposes 
    function onEndRequest(sender, args) { 
     var lbl = document.getElementById("Label1"); 
     lbl.innerHTML = args.get_error().message; 
     args.set_errorHandled(true); 
    } 
</script> 

下面是一些文檔:

Customizing Error Handling for ASP.NET UpdatePanel Controls

Error Handling Customization for ASP.NET UpdatePanel

+0

你的第一個例子,AsyncPostBackErrorMessage,不會捕捉這些超時錯誤。這是我發佈我的問題之前嘗試過的最後一件事......它會抓住任何其他常規異常,但現在看來,該方法是由在更新面板繼續運行,並正常完成回傳叫,而服務器說「哎,這個時間太長,這裏有一個500錯誤」 – Matt

+0

哦,所以IIS已超時? –

+0

我......認爲是的。實際上,在這種情況下,它是我本地盒子上的IISExpress。 – Matt