【问题标题】:Timeout Errors on an UpdatePanel skip Appliation_Error - how do I capture them?UpdatePanel 上的超时错误跳过 Application_Error - 我如何捕获它们?
【发布时间】:2013-06-25 10:38:21
【问题描述】:

使用一些具有大量更新面板的遗留代码。我们遇到了一些对 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 操作来记录它之外,是否有任何选项可以实际捕获/记录此错误?

【问题讨论】:

    标签: asp.net exception-handling timeout updatepanel


    【解决方案1】:

    我知道你有两种方法:

    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

    【讨论】:

    • 您的第一个示例 AsyncPostBackErrorMessage 不会捕获这些超时错误。这是我在发布我的问题之前尝试的最后一件事......它会捕获任何其他常规异常,但似乎更新面板中回发调用的方法继续运行并正常完成,而服务器说“嘿,这花了太长时间,这是一个 500 错误"
    • 我……是这样认为的。实际上,在这种情况下,它是我本地机器上的 IISExpress。
    猜你喜欢
    • 2017-03-12
    • 2023-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 2021-12-31
    • 2016-01-21
    相关资源
    最近更新 更多