问题
My project is an ASP.NET MVC 4 project.
While in localhost it works fine when I host it in Azure
I get a timeout in ajax calls that take more than 4 minutes.
I am sure that the problem is with azure because it doesn't matter what I'm doing in the server.
even just set Thread.sleep(300000)
I get a timeout.
I read in: https://azure.microsoft.com/en-us/blog/new-configurable-idle-timeout-for-azure-load-balancer/ That
a common practice to keep the connection active for a longer period is to use TCP Keep-alive
and there is no other option for web apps. So I guess that what I need is help to keep alive code in asp.net. I can't figure this out by myself. tried to send every one minute simple ajax call to the server and this doesn't help me so I tried to use TcpKeepAlive like this:
public JsonResult MyLongOperation()
{
HttpWebRequest request =(HttpWebRequest)WebRequest.Create("mySite");
request.Proxy = null;
request.ServicePoint.SetTcpKeepAlive(true, 30000, 5000);
Thread.Sleep(300000);//5 min sleep
return Json("ok",JsonRequestBehavior.AllowGet);
}
Didn't work,i need help please!!
回答1:
Had this problem too, found this, worked for me: https://azure.microsoft.com/en-us/blog/new-configurable-idle-timeout-for-azure-load-balancer/
回答2:
Have you tried request.KeepAlive=true; ?
来源:https://stackoverflow.com/questions/33449600/azure-4-min-timeout-in-web-app