请求超时.Web服务器在指定时间内响应失败 [英] The request timed out. The web server failed to respond within the specified time

查看:102
本文介绍了请求超时.Web服务器在指定时间内响应失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Azure App服务中托管了一个ASP .NET Web应用程序.Web应用程序的功能是从excel读取数据并匹配Azure SQL数据库中的数据,然后通过API发布数据.该应用程序运行良好,但问题是它不会运行更长的时间,它会抛出类似

I have hosted an ASP .NET web app in Azure App service. the function of web app is read the data from excel and match the data in Azure SQL database and post the data via API. The app runs good but the problem is that it wont run for longer time it throws an Error like

500 - The request timed out.
The web server failed to respond within the specified time.

我还增加了Web.Config文件中的执行时间限制.

I have also increased the execution time limit in Web.Config file.

<system.web>
    <customErrors mode="Off" />
    <compilation targetFramework="4.6.1" />
    <httpRuntime maxRequestLength="2097152" executionTimeout="300000" targetFramework="4.6.1" />
</system.web>

任何人都可以在这里帮助我做什么.我能否获得至少1小时的执行时间?

Can any one please help here what I can do for this. Can I get minimum of 1 hour execution time?

推荐答案

由于浏览器而发生此问题.您的代码没有问题,无需修改 httpRuntime .

浏览器具有默认的连接超时,Chrome大约为5分钟,实际测试显示 500-请求超时.大约4分钟.

测试代码

public int test()
{
    try
    {
        DateTime dt1 = DateTime.Now;
        DateTime dt2 = dt1.AddMinutes(10);
        while (DateTime.Now < dt2)
        {
            Thread.Sleep(1000);
            Tick("I am running");
        }
        return 1;
    }
    catch (Exception)
    {
        return -1;
        throw;
    }
}

public void Tick(object data)
{
    _logger.LogInformation(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "    " + data); 
}

现象

大约4分钟左右,浏览器中发生了500个超时错误,但是我发现后端仍在运行并且日志仍在记录.

About 4 minutes or so, a 500 timeout error occurred in the browser, but I found that the backend was still running and the log was still recording.

如果后端需要处理一个小时才能返回结果,则它必须异步返回结果.同步是不可能的,没有理由进行同步,即使浏览器没有超时,也不需要同步返回,浪费资源.

If the backend needs to process for an hour to return the result, it must return the result asynchronously. Synchronization is impossible, there is no reason to synchronize, even if the browser does not time out, you do not need to return synchronously, wasting resources.

要及时返回处理结果,可以使用WebSocket和Ajax轮询或signalr.

To return the processing results in time, you can use WebSocket and Ajax polling, or signalr.

在处理过程中,前端只需要提供加载"提示,然后定期轮询即可查询后端处理结果.如果处理成功,则前端提示将成功更新.

During the processing, the front end only needs to provide the Loading prompt, and then poll regularly to query the back-end processing results. If the processing is successful, the front-end prompt is updated successfully.

这篇关于请求超时.Web服务器在指定时间内响应失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆