asp.net-mvc 增加 Azure Web 应用请求超时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32755403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Increase azure web app request timeout
提问by woggles
Is there any way to increase the request timeout for azure web apps?
有什么方法可以增加 azure web 应用程序的请求超时?
If I delay the request by anything over 2 minutes or so the request fails with no error (blank page returned) or a vague 503 response.
如果我将请求延迟超过 2 分钟左右,则请求失败且没有错误(返回空白页)或模糊的 503 响应。
public ActionResult Index()
{
System.Threading.Thread.Sleep(230000);
return View();
}
I have some long running requests that I need to run (uploading large files/large pdf conversion jobs) - is there any way around this? I'd prefer to avoid using VM hosting is possible. I've tried scaling the web app to basic or standard plans, but it doesn't seem to make any difference.
我有一些需要运行的长时间运行的请求(上传大文件/大 pdf 转换作业) - 有什么办法可以解决这个问题吗?我宁愿避免使用虚拟机托管是可能的。我曾尝试将 Web 应用程序扩展到基本或标准计划,但似乎没有任何区别。
采纳答案by Jeff Sanders - MSFT
No, you cannot increase the timeout for Azure App Services (it is 230 seconds). You can move to a cloud services or IIS hosted on a VM where you have control over those settings. You can also move to an async model where the client makes a request, gets some sort of ticket or identifier that is can poll back to see if the processing is done. There are many examples of async type models for web apps out there you can choose from. Ref:https://social.msdn.microsoft.com/Forums/en-US/05f254a6-9b34-4eb2-a5f7-2a82fb40135f/time-out-after-230-seconds?forum=windowsazurewebsitespreview
不,您不能增加 Azure 应用服务的超时时间(230 秒)。您可以转移到托管在虚拟机上的云服务或 IIS,您可以在其中控制这些设置。您还可以移动到异步模型,在该模型中客户端发出请求,获取某种票证或标识符,可以轮询以查看处理是否完成。有许多 Web 应用程序的异步类型模型示例可供您选择。参考:https: //social.msdn.microsoft.com/Forums/en-US/05f254a6-9b34-4eb2-a5f7-2a82fb40135f/time-out-after-230-seconds?forum =windowsazurewebsitespreview
回答by unconnected
Hope this would be some help https://azure.microsoft.com/en-us/blog/new-configurable-idle-timeout-for-azure-load-balancer/. But I think it's bad idea keep request while some heavy job being executed. Imho, you'd better implement background job and check it status from client from time to time.
希望这会有所帮助https://azure.microsoft.com/en-us/blog/new-configurable-idle-timeout-for-azure-load-balancer/。但我认为在执行一些繁重的工作时保留请求是个坏主意。恕我直言,您最好实施后台作业并不时从客户端检查其状态。
回答by Jake OPJ
You can deploy the web app using the automation script and add this line under "resources":
您可以使用自动化脚本部署 Web 应用程序并在“资源”下添加以下行:
{
"name": "WEBSITES_CONTAINER_START_TIME_LIMIT",
"value": 1800
},
where value is by default 230, but can be increased up to 1800. You can also add a New Setting under Application Settings, named WEBSITES_CONTAINER_START_TIME_LIMIT and with the value of seconds you want.
其中 value 默认为 230,但可以增加到 1800。您还可以在 Application Settings 下添加一个名为 WEBSITES_CONTAINER_START_TIME_LIMIT 的新设置,并使用所需的秒值。
回答by quinvit
You can use my trick code here to by-pass 230s limit. In summary, we just keep writing empty html value "\r\n" to response to let ALB know that we are returning data, but actually we are processing the request.
您可以在此处使用我的技巧代码绕过 230 秒限制。综上所述,我们只是不断地写空的html值“\r\n”来响应让ALB知道我们正在返回数据,但实际上我们正在处理请求。
回答by Aram
Try making your action Async if it is supposed to be long running to avoid deadlocks on your web server:
如果应该长时间运行,请尝试使您的操作异步以避免 Web 服务器上的死锁:
public async Task<ActionResult> Index()
{
await Task.Delay(230000);
return View();
}
And you can set script timeout in the code in the controller:
您可以在控制器的代码中设置脚本超时:
HttpContext.Current.Server.ScriptTimeout = 300;
Note that HttpContext is instantiated on a per request basis, so it would be back to the default value on the next request
请注意,HttpContext 是基于每个请求实例化的,因此它会在下一个请求时恢复为默认值
回答by Manraj
You have to some changes in web.config
您必须对 web.config 进行一些更改
<system.webServer>
<monitoring>
<triggers>
<statusCode>
<addstatusCode="500"subStatusCode="0"win32StatusCode="0"
count="10"timeInterval="00:00:30" />
</statusCode>
</triggers>
<actionsvalue="Recycle" />
</monitoring>
For more:
更多信息:

