title: C# WebClient NTLM authentication starting for each request
body: <p>Consider a simple C# NET Framework 4.0 application, that:</p>
  
  <ul>
  <li>uses WebClient</li>
  <li>authenticates using NTLM (tested on IIS 6.0 and IIS 7.5 server)</li>
  <li>retrieves a string from an URL multiple times using DownloadString()</li>
  </ul>
  
  <p>Here's a sample that works fine:</p>
  
  <pre><code>using System;
  using System.Net;
  
  namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
              string URL_status = "http://localhost/status";
  
              CredentialCache myCache = new CredentialCache();
              myCache.Add(new Uri(URL_status), "NTLM", new NetworkCredential("username", "password", "domain"));
  
              WebClient WebClient = new WebClient();
              WebClient.Credentials = myCache;
  
              for (int i = 1; i &lt;= 5; i++)
              {
                  string Result = WebClient.DownloadString(new Uri(URL_status));
                  Console.WriteLine("Try " + i.ToString() + ": " + Result);
              }
  
              Console.Write("Done");
              Console.ReadKey();
          }
      }
  }
  </code></pre>
  
  <p><strong>The problem:</strong></p>
  
  <p>When enabling tracing I see that the NTLM authentication does not persist.</p>
  
  <p>Each time Webclient.DownloadString is called, NTLM authentication starts (server returns "WWW-Authenticate: NTLM" header and the whole authenticate/authorize process repeats; there is no "Connection: close" header).</p>
  
  <p>Wasn't NTLM supposed to authenticate a connection, not a request?</p>
  
  <p>Is there a way to make WebClient reuse an existing connection to avoid having to re-authenticate each request?</p>