title: Authenticated HttpWebRequest with redirection, persisting credentials?
body: <p>My ASP.NET 2.0 app creates a <code>HTTPWebRequest</code> to a site within a company's intranet, which uses NTLM authentication. The credentials passed are for a service account, which is authenticated on the domain successfully (the security log confirms this)</p>
  
  <p>Some abbreviated code follows..</p>
  
  <pre><code>HttpWebRequest req = WebRequest.Create(queryUrl) as HttpWebRequest;
  NetworkCredential cred = new NetworkCredential(username,
                  pwd, domain); 
  req.Credentials = cred;
  
  HttpWebResponse response = req.GetResponse() as HttpWebResponse;
  </code></pre>
  
  <p>As part of the request, there are a couple of redirections (within the same domain) to the final response - which is handled OK on my dev machine (Windows 2k)</p>
  
  <p>When this request is created from my deployment environment (Windows 2k3), I get a 401 Unauthorized error returned from the site, seemingly after the first redirect code is returned (301 Moved), and my request object attempts to follow the redirect.</p>
  
  <p>So basically, does anyone know of any issues surrounding authenticated HttpWebRequests that follow redirections?</p>
  
  <p><strong>PS</strong> - The obvious workaround is to simply request the page redirected to - but I the admins in charge of the intranet site want to monitor my app's usage by redirecting me through a specific page.</p>