UpdatePanel上的超时错误跳过Appliation_Error - 我如何捕获它们?

时间:2013-06-27 19:15:40

标签: asp.net exception-handling timeout updatepanel

使用一些具有大量UpdatePanel的遗留代码。我们遇到的问题是UpdatePanels的一些回发超时(超过默认的90秒限制),我想知道何时发生这种情况。

我们当前正在记录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操作来记录它?

1 个答案:

答案 0 :(得分: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