The remote certificate is invalid according to the validation procedure 远程证书验证无效

The remote certificate is invalid according to the validation procedure 远程证书验证无效

The remote certificate is invalid according to the validation procedure   根据验证过程中远程证书无效 

I'm calling an ASP.NET web service from an ASP.NET web application. The two applications are on different servers. The web service requires SSL and presents the application with a self-signed certificate. Since this is an internal app, I want the client application to trust the web service and its self-signed cert. 我调用一个 ASP.net Web服务从一个ASP.NET Web应用, 这两个应用在不通的服务器上, Web Service请求了一个自签名的证书, 这事个内网app,我希望客户端应用信任web service的自签名证书。 
There are lots of suggestions on how to do this in your code by coding a delegate method to accept all server certificates regardless of origin:

这里是关于解决这个问题最多的方法, 就是 在你代码里通过委托方法的方式默认接受所有服务器证书。 

ServicePointManager.ServerCertificateValidationCallback =
delegate(object sender, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors) { return true; };
I don't want to do this, though, because this same code will be rolled out to production and it seems sloppy to me to allow all certificates to validate carte blanche.
我不想这么做, 因为这样的代码放到生产环境允许所有证书验证通过太过敷衍和马虎并且不负责任。 

So, I set out to download the internal SSL certificate and install it in the client computer's Trusted Root Certification Authorities cache. That still doesn't work!
所以, 我下载了内网证书并且在客户端计算机安装到了信任的整数缓存, 但是依然不正常。 
Thanks to Ferry Onderwater's entry at  http://www.arcencus.nl/Blogs/tabid/105/EntryID/39/Default.aspx, I see now where I went astray. By default, the Certificate snap-in installs certificates for the current user only. I needed all users to trust the certificate.
感谢 Ferry Onderwater's  的   http://www.arcencus.nl/Blogs/tabid/105/EntryID/39/Default.aspx 这片文章, 看起来是我现在想要的, 因为默认情况下,整数是安装在当前用户的, 我需要让所有用户都信任这个证书。 
解决方案:
  • 启动一个MMC.
  • File --> Add/Remove Snap-In...  文件-->添加删除  单元
  • Click Add...   点击添加
  • Choose Certificates and click Add.  选择证书并添加 
  • Check the "Computer Account" radio button. Click Next.  选择计算机 账号  按钮 点击下一步
  • Choose the client computer in the next screen. Click Finish.  选择客户端计算机在下一个屏幕, 点击完成 
  • Click Close. 点击关闭
  • Click OK.  点击确定 
  • NOW install the certificate into the Trusted Root Certification Authorities certificate store. This will allow all users to trust the certificate.  现在 安装证书到信任的根证书授权证书存储 (不同的系统中文翻译不太一样, 大概意思明白就行。 ) 然后允许所有证书信任此证书。 
  •   
posted @ 2019-04-22 19:17 麦壳饼 阅读( ...) 评论( ...) 编辑 收藏
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!对于您遇到的问题,出现 "The SSL connection could not be established, see inner exception. The remote certificate is invalid" 错误消息通常表示 SSL 证书无效导致无法建立安全连接。 出现此错误的原因可能有几种: 1. 证书过期或无效:请确保远程服务器的 SSL 证书是有效的,并且其颁发机构受信任。可以使用浏览器或命令行工具(如 OpenSSL)检查证书的有效性。 2. 证书链不完整:有时,服务器可能未正确配置 SSL 证书链。这可能会导致客户端无法验证服务器的证书。您可以尝试手动将证书链添加到代码中,以确保完整性。 3. 代理配置问题:如果您使用代理进行网络连接,可能是代理配置问题导致 SSL 连接失败。请确保代理配置正确,并且代理服务器也可以正确处理 SSL 连接。 解决此问题的一种方法是在 .NET Core 代码中禁用 SSL 证书验证,这样可以绕过证书验证错误。但这只是权宜之计,并不建议在生产环境中使用。以下是一个示例代码片段,用于禁用证书验证: ```csharp using System; using System.Net.Http; using System.Net.Http.Headers; using System.Net.Security; using System.Security.Cryptography.X509Certificates; // 创建 HttpClientHandler 实例,并设置 ServerCertificateCustomValidationCallback var handler = new HttpClientHandler(); handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true; // 创建 HttpClient 实例,使用上面创建的 handler var client = new HttpClient(handler); // 发送请求 var response = await client.GetAsync("https://example.com"); ``` 请注意,禁用证书验证可能会带来安全风险,请在了解风险的情况下谨慎使用。 希望这些信息能对您有所帮助!如果您有任何其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值