开发者

C# WebClient HTTPS Authentication Policy

开发者 https://www.devze.com 2023-01-26 02:47 出处:网络
All - I\'m using C#\'s WebClient class to gain access to a resource on a remote server via https.The resource I am interested in is a file on the remote ser开发者_如何转开发ver.I\'m using the followi

All -

I'm using C#'s WebClient class to gain access to a resource on a remote server via https. The resource I am interested in is a file on the remote ser开发者_如何转开发ver. I'm using the following call to gain access to the file:

WebClient client = new WebClient();
client.DownloadData("https://someuri/file.txt");

When calling the above code I get the an System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure. I have manually visted the site via IE and added the cert. as a trusted issuer and can browse to the resource without an issue in IE. Does C# not use the standard windows certificate store ? or do I have to write my own CertificatePolicy?. I'd really like to use the built in authentication algorithms.

Thanks in advance.


In order to get this working properly you one can't just accept the the end certificate in the browser. You must use the cmd: mmc console to load certificates into the Machines trust store rather then just the users trust store.


Are you running this code through ASP.Net? If so, you may have to install the cert for the Local Computer, as the cert you installed for your login cant be used by ASP.net

0

精彩评论

暂无评论...
验证码 换一张
取 消