title: asp.net core 2 Web API timeout issue
body: <p>I have a .net core web api and one of the end point runs a stored procedure that takes 3-4 minutes to complete. API is deployed to IIS. </p>
  
  <p>When I make a httpGet , I get 502 Bad Gateway error. Looking at the IIS Log, the error is actually timeout. This from IIS Log: </p>
  
  <p><strong><code>2018-11-28 17:24:48 10.71.12.59 GET /api/meetingreport fromDate=11/01/2018&amp;toDate=11/30/2018&amp;tradingGroup=All&amp;symbol=&amp;reviewed= 16000 - 10.6.50.61 Mozilla/5.0+(Windows+NT+6.1;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/64.0.3282.140+Safari/537.36 - 502 3 12002 120029</code></strong></p>
  
  <p>Error code 12202 is for <a href="https://docs.microsoft.com/en-us/windows/desktop/WinHttp/error-messages" rel="noreferrer">ERR_WINHTTP_TIMEOUT</a>. 
  Timeout happens after 2 mins. Request taking under than 2 mins works fine. I checked it by adding a thread.sleep of over and under 2 mins. </p>
  
  <pre><code>[HttpGet("")]
          public async Task&lt;IActionResult&gt; Get([FromQuery(Name = "fromDate")] DateTime fromDate, 
                      [FromQuery(Name = "toDate")] DateTime toDate, [FromQuery(Name ="tradingGroup")]string tradingGroup, [FromQuery(Name = "symbol")]string symbol, [FromQuery(Name = "reviewed")]string reviewed)
          {
              try
              {
                  if (fromDate == DateTime.MinValue || toDate == DateTime.MinValue) return BadRequest("fromDate and toDate is a required Field");
                  tradingGroup = tradingGroup == "All" ? tradingGroup.Replace("All", "") : tradingGroup;
                  tradingGroup = tradingGroup ?? string.Empty;
                  symbol = symbol ?? string.Empty;
                  var result = await _meetingReportRepository.GetMeetingReport(fromDate, toDate, tradingGroup, symbol, reviewed);
                  Thread.Sleep(132000); // 2.2 minutes
                      return Ok(result);
              }
              catch (Exception ex)
              {
              }
              return BadRequest($"Couldn't Genererate Report");
  
          }
  </code></pre>
  
  <p>This is the error from POSTMAN. </p>
  
  <p><a href="https://i.stack.imgur.com/dNkJ6.png" rel="noreferrer"><img src="https://i.stack.imgur.com/dNkJ6.png" alt="enter image description here"></a></p>
  
  <p>How can I increase the timeout to 10 minutes ? Any pointers?  There is no Web.config file. </p>
  
  <p>Following <a href="https://stackoverflow.com/questions/37474309/timeouts-with-long-running-asp-net-mvc-core-controller-httppost-method/38507709#38507709">this</a> post I updated my program.cs to add KeepAliveTimeout of 10 minutes. But this didn't help . My request is still timing out after 2 mins. </p>
  
  <pre><code>public static IWebHost BuildWebHost(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
              .UseStartup&lt;Startup&gt;()
              .UseKestrel( o=&gt; { o.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(10); })
              .Build();
  </code></pre>
  
  <p><strong>EDIT 1:</strong> 
  When deployed to IIS, a web.config file is created and it has content as below: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;location path="." inheritInChildApplications="false"&gt;
      &lt;system.webServer&gt;
        &lt;handlers&gt;
          &lt;add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /&gt;
        &lt;/handlers&gt;
        &lt;aspNetCore processPath="dotnet" arguments=".\project.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" /&gt;
      &lt;/system.webServer&gt;
    &lt;/location&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I am going to add timeout here to see if it works. </p>
  
  <p><strong>EDIT 2:</strong>
  adding requestTimeout did the trick. IIS is very loyal to web.config :). My issue is resolved.</p>
  
  <pre><code>&lt;aspNetCore requestTimeout="00:20:00" processPath="dotnet" arguments=".\project.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" /&gt;
  </code></pre>