简体   繁体   English

C#WebClient HTTPS身份验证策略

[英]C# WebClient HTTPS Authentication Policy

All - 全部-

I'm using C#'s WebClient class to gain access to a resource on a remote server via https. 我正在使用C#的WebClient类通过https获得对远程服务器上资源的访问。 The resource I am interested in is a file on the remote server. 我感兴趣的资源是远程服务器上的文件。 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. 当调用上面的代码时,我得到一个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. 我已经通过IE手动访问了该网站并添加了证书。 as a trusted issuer and can browse to the resource without an issue in IE. 作为受信任的发行者,并且可以浏览到资源,而IE中没有问题。 Does C# not use the standard windows certificate store ? C#是否不使用标准的Windows证书存储区? or do I have to write my own CertificatePolicy ?. 还是我必须编写自己的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. 您必须使用cmd:mmc控制台将证书加载到计算机信任存储中,而不是仅将证书加载到用户信任存储中。

Are you running this code through ASP.Net? 您是否通过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 如果是这样,则可能必须为本地计算机安装证书,因为ASP.net无法使用为登录名安装的证书。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM