C# WebClient HTTPS 身份验证策略
所有 -
我正在使用 C# 的 WebClient
类通过 https 访问远程服务器上的资源。我感兴趣的资源是远程服务器上的文件。我使用以下调用来访问该文件:
WebClient client = new WebClient(); client.DownloadData("https://someuri/file.txt");
调用上述代码时,我收到 System.Security.Authentication.AuthenticationException: 根据验证过程,远程证书无效。 我已通过 IE 手动访问该网站并添加了证书。作为受信任的颁发者,可以在 IE 中毫无问题地浏览资源。 C# 不使用标准 Windows 证书存储吗?或者我必须编写自己的CertificatePolicy
?我真的很想使用内置的身份验证算法。
提前致谢。
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 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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了使其正常工作,您不能只接受浏览器中的最终证书。您必须使用 cmd: mmc 控制台将证书加载到计算机信任存储中,而不仅仅是用户信任存储中。
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.
您是否通过 ASP.Net 运行此代码?如果是这样,您可能必须为本地计算机安装证书,因为 ASP.net 无法使用您为登录安装的证书
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