title: The remote server returned an error: (401) Unauthorized at System.Net.HttpWebRequest.GetResponse()
body: <p>I am trying to run following code it works fine when runs on localhost IIS but returns error when hosted on my web server IIS</p>
  
  <p><strong>Error</strong> : -- The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at _Default.btnsubmit_Click(Object sender, EventArgs e) in e:\WebSite1\Default.aspx.cs:</p>
  
  <pre><code>try
  {
  
  var webAddr = "http://serviceserver/someService";
  var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
  httpWebRequest.ContentType = "text/xml";
  httpWebRequest.ContentLength = 0;
  httpWebRequest.Method = "GET";
  
  httpWebRequest.Credentials = new NetworkCredential("user", "password");
  var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  using (var streamReader = new treamReader(httpResponse.GetResponseStream()))
     {
         var result = streamReader.ReadToEnd();
         Label1.Text = result;
     }
  }
  catch (Exception ex)
  {
  Response.Write(ex.Message);
  Response.Write(ex.StackTrace);
  Response.Write(ex.InnerException);
  }
  </code></pre>
  
  <p><strong>Update</strong>
     The above service URL is WCF service and it is secured via transport credentials in windows 
  I am trying to hit this URL via my web application and passing my credentials as Network Credentials.
  When I run this web application on my local machine it runs fine and returns the required data.
  But when I host this application I got above stated error. Am I doing something wrong.</p>