【问题标题】:Timeout issue for long requests on ajax POSTajax POST 上的长请求超时问题
【发布时间】:2013-07-01 01:29:40
【问题描述】:

所以我有一个 .NET MVC 项目,它带有一个从 Ajax POST 调用的更新控制器,它可能需要很长时间才能运行,这会导致超时异常。

当我在本地机器上调试它时,它运行良好,但是 - 当我将它发布到我的天蓝色网站并从那里更新它时,请求永远不会成功完成并且 Chrome 的控制台报告:

POST http://mysiteaddress/Admin/UpdateLibrary/Update?Length=13 504 (Proxy Timeout ( This operation returned because the timeout period expired. )) 

在 Firefox 中的远程桌面上尝试相同的操作会导致控制台报告:

[07:42:13.856] POST http://mysiteaddress/Admin/UpdateLibrary/Update?Length=13 **[HTTP/1.1 502 Bad Gateway 182940ms]** 

我尝试在我的 web.config 文件中设置较长的超时时间

    <httpRuntime executionTimeout="2000"/>

在我的 ajax 调用中

    $.ajax({
        url: this.action,
        type: 'POST',
        data: $(this).serialize(),
        success: function (data) {
            document.write(data);
        },
        failure: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest);
                console.log(textStatus);
                console.log(errorThrown);
        },
        timeout: 2000000 //Milliseconds
    });

但没有快乐。

【问题讨论】:

    标签: asp.net-mvc jquery azure timeout


    【解决方案1】:

    所以这并不是真正的修复,而是一种解决方法。我没有发出一个单一的长请求,而是让我的 javascript 反复查询一个 ActionResult,它返回一些 json 来决定我的长时间运行的进程是否已经完成。完成后,我将浏览器重定向到结果屏幕。

        $.updateProgressbar = function () {
            $.get('@Url.Action("GetStatus", "UpdateLibrary", new { countryId = countryId }, Request.Url.Scheme)', function (data) {
                $('#progressbar').progressbar('value', data.progress)
                if (data.currentItem != null) {
                    $('#currentWorkItem').text('@l12.View_Update_currentlyWorking' + data.currentItem);
            }
                if (data.progress == 100) {
                    window.location =
                        '@Url.Action("UpdateResults", "UpdateLibrary", new { countryId = countryId }, Request.Url.Scheme)';
                } else {
                    setTimeout($.updateProgressbar, 5000);
                }
            });
        };
    
        $(function () {
            $("#progressbar").progressbar({ value: 0 });
            setTimeout($.updateProgressbar, 5000);
        });
    

    【讨论】:

      【解决方案2】:

      看起来在您的本地网络上到外部 azure 站点,您正在通过代理/网关服务器出去。贵公司是否有任何可能拦截和阻止请求的允许/禁止网站的阻止列表或白名单?

      【讨论】:

      • 你说得对,我确实通过代理连接。我们的服务器上似乎没有任何黑名单。我确实进入了我们的服务器设置并将 Web 请求的默认连接超时更改为更长。这将其转换为我在远程桌面上收到的相同错误 - Failed to load resource: the server responded with a status of 502 (Bad Gateway)
      猜你喜欢
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 2012-01-22
      • 2017-03-22
      • 2013-09-05
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      相关资源
      最近更新 更多