title: WebClient accessing page with credentials
body: <p>I am trying to access a webpage on a same domain / same asp.net application, that is password protected. Credentials are the same both for webpage firing this call and webpage being accessed.</p>
  
  <p>Here is the code, and I don't know why I always end up with a login form html code?</p>
  
  <pre><code>using (WebClient client = new WebClient())
  {
      client.QueryString.Add("ID", "1040"); //add parameters
      //client.Credentials = CredentialCache.DefaultCredentials;
      //I tried to add credentials like this
      client.Credentials = new NetworkCredential("username", "password");
  
      string htmlCode = client.DownloadString("http://domain.loc/testpage.aspx");
  }
  </code></pre>