MSDeploy API - 允许不受信任的证书

时间:2012-10-21 07:53:51

标签: msdeploy webdeploy microsoft-web-deploy

我正在尝试通过c#使用MSDeploy API运行远程MSDeploy命令。

我正在运行以下内容:

//test connection by pulling down file list
var sourceBaseOptions = new DeploymentBaseOptions();
var destBaseOptions = new DeploymentBaseOptions
                            {
                                ComputerName = "https://mysite.com/msdeploy.axd?sitename=siteName",
                                UserName = "username",
                                Password = "password",
                                AuthenticationType = "Basic"
                            };
var syncOptions = new DeploymentSyncOptions();       

var deployment = DeploymentManager.AvailableProviderFactories;
DeploymentObject deploymentObject = DeploymentManager.CreateObject("dirPath", Settings.TemporaryStoragePath, sourceBaseOptions);
// collect and report all the changes that would happen
var changes = deploymentObject.SyncTo(destBaseOptions, syncOptions);

因为我正在运行不受信任的证书,所以会抛出异常。如何告诉MSDeploy不要担心证书? (即基于代码的“AllowUntrustedCertificate = true”)

1 个答案:

答案 0 :(得分:5)

看来我必须设置ServicePointManager回调服务器证书验证。

在我调用MSDeploy之前放置以下内容似乎有效:

ServicePointManager.ServerCertificateValidationCallback = (s, c, chain, err) =>
{
    return true;
};