web developer tips (41):用自颁发的证书连接到远程IIS服务器
要么通过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)
Object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors
)
于是,接受所有服务器证书,你需要设置一个ServicePointManager的回调来来验证一个服务器的证书,如下所示:
bool RemoteCertificateValidationCallbackCheck(
Object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors
)
{
return true;
}
关于这个“委托”可以参考MSDN文档:
1、RemoteCertificateValidationCallback Delegate
2、ServicePointManager.ServerCertificateValidationCallback Property
更多文章见:守望轩[http://www.watch-life.net/]