title: X509Certificate.LoadStoreFromFile(): The computer must be trusted for delegation and the current user account must be configured to allow delegation
body: <p>I am facing an issue while trying to load a p12 certificate file in a C# MVC web application when login is through an AD account.</p>
  
  <p>The error we get when loading the certificate is: <strong>The computer must be trusted for delegation and the current user account must be configured to allow delegation.</strong></p>
  
  <p>The code for loading the certificate:</p>
  
  <pre><code>ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
  
  var handler = new WebRequestHandler();
  
  var certificate = new X509Certificate2Collection();
  certificate.Import(@"D:\certificate.p12", "password", X509KeyStorageFlags.DefaultKeySet);
  handler.ClientCertificates.AddRange(certificate);
  handler.ServerCertificateValidationCallback = ValidateServerCertificate;
  
  var client = new HttpClient(handler)
  {
      BaseAddress = new Uri(chargeCodeServer)
  };
  </code></pre>
  
  <p>We get an exception at the following line:</p>
  
  <pre><code>certificate.Import(@"D:\certificate.p12", "password", X509KeyStorageFlags.DefaultKeySet);
  </code></pre>
  
  <p>The stack trace:</p>
  
  <pre><code>The requested operation cannot be completed. The computer must be trusted for delegation and the current user account must be configured to allow delegation.
  at System.Security.Cryptography.X509Certificates.X509Certificate2Collection.LoadStoreFromFile(String fileName, String password, UInt32 dwFlags, Boolean persistKeyContainers)
  at System.Security.Cryptography.X509Certificates.X509Certificate2Collection.Import(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
  </code></pre>
  
  <p>The same code runs fine in a console application.</p>
  
  <p>The certificate is being loaded for calling a web API over https.</p>
  
  <p>Please let me know if any more information is needed.</p>