Question

I am trying to run remote MSDeploy commands using the MSDeploy API through c#.

I am running the following:

//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);

It is throwing an exception as I'm running an untrusted certicate. How do I tell MSDeploy not to worry about the certificate? (ie a code based "AllowUntrustedCertificate=true")

Was it helpful?

Solution

It appears I have to set the ServicePointManager call back for server certificate validation.

Placing the below before I call MSDeploy seems to work:

ServicePointManager.ServerCertificateValidationCallback = (s, c, chain, err) =>
{
    return true;
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top