微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – Azure ASP .net WebApp请求超时

我已经为Azure App服务部署了一个ASP .net MVC Web应用程序.

我从我的网站做一个GET请求到一些从DB(DbContext)获取数据的控制器方法.有时从DB获取数据的过程可能需要超过4分钟.这意味着我的请求超过4分钟没有动作.之后,Azure杀死了连接 – 我收到消息:

500 – The request timed out.

The web server Failed
to respond within the specified time.

这是一个方法示例:

[HttpGet]
    public async Task<JsonResult> LongGet(string testString)
    {            
       var task = Task.Delay(360000);
        await task;            
        return Json("Woke",JsonRequestBehavior.AllowGet);
    }

我看到很多这样的问题,但我没有回答:

Not working 1
不能给其他链接 – 声誉太低.

我已经阅读了这个article – 它关于Azure Load Balancer,它不适用于webapps,但是它编写的在Azure webapp中处理我的问题的常见方法是使用TCP Keep-alive.所以我改变了我的方法

[HttpGet]
    public async Task<JsonResult> LongPost(string testString)
    {
        ServicePointManager.SetTcpKeepAlive(true,1000,5000);
        ServicePointManager.MaxServicePointIdleTime = 400000;
        ServicePointManager.FindServicePoint(Request.Url).MaxIdleTime = 4000000;
       var task = Task.Delay(360000);
        await task;            
        return Json("Woke",JsonRequestBehavior.AllowGet);
    }

但仍然会收到相同的错误.
我正在使用简单的GET请求

GET /Home/LongPost?testString="abc" HTTP/1.1
Host: longgetrequest.azurewebsites.net
Cache-Control: no-cache
Postman-Token: bde0d996-8cf3-2b3f-20cd-d704016b29c6

所以我正在寻找答案我做错了什么以及如何在Azure Web应用程序中增加请求超时时间.任何帮助是赞赏.

门户上的Azure设置:

网络套接字 – 开

始终开启

应用设置:

SCM_COMMAND_IDLE_TIMEOUT = 3600

WEBSITE_NODE_DEFAULT_VERSION = 4.2.3

解决方法

230秒.而已.这是Azure App Service中的飞行中请求超时.它在平台上硬编码,所以TCP保持活着还是不受限制.

来源 – 请见David Ebbo的答案:
https://social.msdn.microsoft.com/Forums/en-US/17305ddc-07b2-436c-881b-286d1744c98f/503-errors-with-large-pdf-file?forum=windowsazurewebsitespreview

There is a 230 second (i.e. a little less than 4 mins) timeout for requests that are not sending any data back. After that,the client gets the 500 you saw,even though in reality the request is allowed to continue server side.

不知道更多的应用程序,很难建议一种不同的方法.然而,很清楚的是,你需要一种不同的方法

也许返回一个202接受替换与一个位置标题来轮询结果以后?

原文地址:https://www.jb51.cc/csharp/91220.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐