【问题标题】:how to handle PageRequestManagerTimeoutException in ASP.net Web Application?如何处理 ASP.net Web 应用程序中的 PageRequestManagerTimeoutException?
【发布时间】:2012-06-30 16:04:53
【问题描述】:

我正在开发一个 ASP.NET Web 应用程序,该应用程序尝试通过登录服务器从远程服务器下载一些文件。当我尝试下载文件时,它适用于小文件,但下载 750 KB 的文件时显示以下异常。

我正在定义HTTPRequest Timout = System.Threading.Timeout.Infinite;

我正在使用此代码从服务器读取文件

byte[] buffer = new byte[32768];
            using (Stream input = getResponse.GetResponseStream())
            {
                using (FileStream output = new FileStream(saveTo1, FileMode.OpenOrCreate))
                {
                    int bytesRead;

                    while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        output.Write(buffer, 0, bytesRead);
                    }
                }
            }

什么可能造成这个问题?

当我点击IgnoreContinue时,它会继续下载 进一步顺利。我该如何克服这个问题?

提前致谢。 :)

【问题讨论】:

    标签: c# javascript asp.net


    【解决方案1】:

    如果需要处理超时异常,可以用javascript处理。将此添加到您的页面。

    <script type="text/javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(requestEndHandler );
    
    // This function will handle the end request event
    function requestEndHandler(sender, args) {
       if( args.get_error() ){
          document.getElementById("errorMessageLabel").innerText = 
             args.get_error().description;
           args.set_errorHandled(true);
       }
    }
    
    </script>
    ...
    
    <span id="errorMessageLabel"></span>
    

    此外,如果您愿意,您可以通过 sdding AsyncPostBackTimeOut="600"//Time 到您的脚本管理器来增加 AsyncPostBackTimeOut。:

    <asp:ScriptManager ID="ScriptManager1" runat="server"
    
    AsyncPostBackTimeOut="600" >
    
    </asp:ScriptManager>  
    

    【讨论】:

    • 我处理超时的方法是将其值设置为-1,即无限。
    • 如果不是非常重要,不要使用无限价值。有一个有限的价值是一个安全的赌注。
    • 这个时间值以毫秒为单位
    • 没有秒,该功能有帮助吗?
    • 哇,好用。不是功能,而是设置AsyncPostBackTimeOut="60"。谢谢:)
    猜你喜欢
    • 2021-05-26
    • 1970-01-01
    • 2012-06-08
    • 2012-05-13
    • 2015-02-09
    • 2021-07-14
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多