title: HttpWebRequest, Keep-Alive as Fiddler does?
body: <p>Using HttpWebRequest, I'm trying to query a secured (negotiate) url behind a load balancing setup in round-robin mode (two IIS 7.5 servers). Seems simple enough, but I have some problems.</p>
  
  <p>The first anonymous request goes on one server and the negotiate part goes on the other. The problem is that it takes about six seconds between these two requests, so it is way too long. Trying to diagnose the delay, I realized that, going through Fiddler's proxy, all the requests went on the same server, so it took less than one second total. If I disable Fiddlers option "reuse server connections", then my requests have the same behavior as without Fiddler and it takes forever.</p>
  
  <p>Googling this, I ended up on this link: <a href="http://fiddler2.com/blog/blog/2013/02/28/help!-running-fiddler-fixes-my-app-" rel="nofollow">http://fiddler2.com/blog/blog/2013/02/28/help!-running-fiddler-fixes-my-app-</a></p>
  
  <p>I know that Fiddler is using sockets and its own connection pool, but is there a way to reproduce the same behavior using .NET HttpWebRequest so that my requests (anonymous and negotiate) will reuse connections and end up on the same server?</p>
  
  <p>Here is a quick test that takes about 70 seconds to complete without Fiddler, and about 2 seconds going through Fiddler...</p>
  
  <p>Also, please note that it isn't a Proxy detection delay and that sticky session are disabled on the nlb.</p>
  
  <pre><code>    public void Main(string[] args)
      {
          int i = 0;
  
          while (i &lt; 10)
          {
              HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://nlb/service.asmx");
              HttpWebResponse response;
  
              wr.KeepAlive = true;
              wr.UseDefaultCredentials = true;
              response = (HttpWebResponse)wr.GetResponse();
  
              using (StreamReader sr = new StreamReader(response.GetResponseStream()))
              {
                  Console.WriteLine(sr.ReadToEnd());
              }
  
              response.Close();
  
              i++;
          }
      }
  </code></pre>
  
  <p>This is another proof that Fiddler is plain awesome!</p>
  
  <p>Thanks for any advice.</p>