title: 401 Authentication error while running C# Application executing HttpWebRequest
body: <p>I would like to know how can I fix this issue wherein a WebApp running on IIS 7/8 with Windows Authentication is throwing 401 error while executing HttpWebRequest to another site. This WebApp works fine if I run it locally i.e debug mode.</p>
  
  <p>Here is the code snippet</p>
  
  <pre><code>HttpWebRequest webReq;
  webReq = (HttpWebRequest)WebRequest.Create("http://sharepoint_site/_vti_bin/listdata.svc/mylist);
  webReq.Accept = "application/json";
  webReq.UseDefaultCredentials = true;
  webReq.Credentials = CredentialCache.DefaultNetworkCredentials;
  //webReq.Credentials = new NetworkCredential("user","password","domain");
  
  webReq.Method = "GET";
  webReq.KeepAlive = true;
  Stream objStream = webReq.GetResponse().GetResponseStream();
  StreamReader objReader = new StreamReader(objStream);
  HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
  </code></pre>
  
  <p>I was also able to make it work by adding BackConnectionHostNames entry in the registry</p>
  
  <p>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0</p>
  
  <p>but I need to pass in the credentials (commented above) which I don't like because I don't want to use my account or any service account.</p>
  
  <p>I want the WebApp to use DefaultNetworkCredentials or DefaultCredentials. I enabled Windows Authentication and NTLM provider on the IIS of the machine hosting this WebApp.</p>
  
  <p>Any help will be greatly appreciated, thanks and more power to this community.</p>