2014-02-18 55 views
1

瞭解這一點,但沒有看到如何實際延長時間限制的迴應: https://devcenter.heroku.com/articles/request-timeout如何延長的時間長度HTTP響應

string responseContents = string.Empty; 

//get web request to wait 5 mins 

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 

byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(message); 
request.Method = "POST"; 
request.ContentType = "text/xml;charset=utf-8"; 
request.ContentLength = requestBytes.Length; 

using (Stream requestStream = request.GetRequestStream()) 
{ 
    requestStream.Write(requestBytes, 0, requestBytes.Length); 
    requestStream.Close(); 
} 

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 
{ 
    using (StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default)) 
    { 
     responseContents = sr.ReadToEnd(); 
    } 
} 

問題是,很多東西在服務器回事,需要時間來返回響應,具體取決於文件大小。

回答

1

你可以做到這在web.config中以及

<system.web> 
    <httpRuntime executionTimeout="180" /> 
</system.web> 

編輯:如果您只想爲特定控制器設置它 -

<location path="ControllerName/ActionName"> 
    <system.web> 
     <httpRuntime executionTimeout="180"/> 
    </system.web> 
</location>