相关疑难解决方法(0)

Azure ASP .net WebApp请求超时

我已经将ASP .net MVC Web应用程序部署到Azure App服务.

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

500 - 请求超时.

Web服务器无法在指定时间内响应.

这是一个方法示例:

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

我见过很多像这样的问题,但我没有回答:

不工作1不能 给其他链接 - 声誉太低.

我已经阅读了这篇文章 - 它关于Azure负载均衡器,它不适用于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);
    }
Run Code Online (Sandbox Code Playgroud)

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

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

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

门户网站上的Azure设置: …

c# asp.net-mvc azure

21
推荐指数
1
解决办法
2万
查看次数

标签 统计

asp.net-mvc ×1

azure ×1

c# ×1