title: WebClient DownloadFile access denied
body: <p>I'm trying to download the file to the server, but instead data is written to the error. Please tell me what is wrong. When i use this code on "<a href="http://localhost:xxx" rel="nofollow">http://localhost:xxx</a>" everything is working fine. <code>
  WebClient myWebClient = new WebClient();
  myWebClient.DownloadFile(remoteUri, Server.MapPath("~/test/" + "test.xml"));
  </code></p>
  
  <p>I updated my question. Here is my full code:</p>
  
  <pre><code>string path1 = "certificate1.p12";
  string path2 = "certificate2.crt";
  X509Certificate2 cert1 = new X509Certificate2(Server.MapPath(("~/test/") + path1), "", X509KeyStorageFlags.MachineKeySet);
  X509Certificate2 cert2 = new X509Certificate2(Server.MapPath(("~/tets/") + path2));
  CertificateWebClient2 myWebClient = new CertificateWebClient2(cert1, cert2);
  string remoteUri = "https://xxxxx";
  string path = "test.xml";
  myWebClient.UseDefaultCredentials = true;
  myWebClient.DownloadFile(remoteUri, Server.MapPath((@"~/Files/") + path));
  
  
  public class CertificateWebClient : WebClient
  {
      private readonly X509Certificate2 certificate1;
      private readonly X509Certificate2 certificate2;
  
      public CertificateWebClient(X509Certificate2 cert1, X509Certificate2 cert2)
      {
          certificate1 = cert1;
          certificate2 = cert2;
      }
  
      protected override WebRequest GetWebRequest(Uri address)
      {
          HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
          System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(Object obj, X509Certificate X509certificate, X509Chain chain, System.Net.Security.SslPolicyErrors errors)
          {
              return true;
          };
  
          request.ProtocolVersion = HttpVersion.Version10;
          request.Method = "Post";
          request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
          request.ContentType = "application/x-www-form-urlencoded";
          request.UseDefaultCredentials = true;
          request.ContentLength = 0;
          request.ClientCertificates.Add(certificate1);
          request.ClientCertificates.Add(certificate2);
          return request;
      }
  }
  </code></pre>