web developer tips (41):用自颁发的证书连接到远程IIS服务器

原文地址:establishing a remote connection to a IIS server with self-issued certificate will require a certificate validation delegate

要么通过WMSvc 要么通过自己的脚本,当你尝试与远程服务器建立一个连接,没有提供受信任的证书,你需要提供证书验证的委托,用来检查不受信任的证书。
http://www.watch-life.net/visual-studio/establishing-a-remote-connection-to-a-iis-server-with-self-issued-certificate.html

这个委托的签名如下:
Namespace: System.Net.Security
Assembly: System (in System.dll)

public delegate bool RemoteCertificateValidationCallback(
Object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors
)

于是,接受所有服务器证书,你需要设置一个ServicePointManager的回调来来验证一个服务器的证书,如下所示:

ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallbackFlag;

bool RemoteCertificateValidationCallbackCheck(
Object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors
)
{
return true;
}

关于这个“委托”可以参考MSDN文档:
1、RemoteCertificateValidationCallback Delegate
2、ServicePointManager.ServerCertificateValidationCallback Property



微信扫描下方的二维码阅读本文

那年今日

2008-09-02 Google Reader 调30条命秘籍 (4 个评论)

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注