0

I am using the below code to deploy via WebDeploy to a Azure website. I can deploy to the same site with WebDeploy with Visual Studio 2013 using the same server and credential information, but when I run the code below it keeps failing and telling me that it was not able to authorize, it's getting a 401. Any ideas way?

var sourceBaseOptions = new DeploymentBaseOptions();
DeploymentBaseOptions destBaseOptions = new DeploymentBaseOptions()
{
    UserName = prf.UserName,
    Password = prf.UserPassword,
    ComputerName = string.Format("https://{0}/MsDeploy.axd?Site={1}", 
                                    prf.PublishUrl, 
                                    prf.MSDeploySite)
};
//-disableLink:AppPoolExtension 
//-disableLink:ContentExtension 
//-disableLink:CertificateExtension 
foreach (var extension in sourceBaseOptions.LinkExtensions
    .Where(ext => ext.Name == "AppPoolExtension"
                || ext.Name == "ContentExtension"
                || ext.Name == "CertificateExtension"))
{
    extension.Enabled = false;
}
sourceBaseOptions.Trace += sourceBaseOptions_Trace;
sourceBaseOptions.TraceLevel = System.Diagnostics.TraceLevel.Verbose;
foreach (var extension in destBaseOptions.LinkExtensions
    .Where(ext => ext.Name == "AppPoolExtension"
                || ext.Name == "ContentExtension"
                || ext.Name == "CertificateExtension"))
{
    extension.Enabled = false;
}

using (var deploymentObject = DeploymentManager.CreateObject(
                                    DeploymentWellKnownProvider.Package,
                                    @"E:\DeployPackages\Site.zip", 
                                    sourceBaseOptions))
{
    //configure deploy target Web site name instead of using -SetParams
    deploymentObject.SyncParameters
        .Single(p => p.Name == "IIS Web Application Name")
        .Value = prf.MSDeploySite;

    DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();
    syncOptions.WhatIf = false;

    // Will fail on this call
    var changes = deploymentObject.SyncTo(DeploymentWellKnownProvider.Auto, 
                                    "", 
                                    destBaseOptions, 
                                    syncOptions);

}
John C
  • 1,761
  • 2
  • 20
  • 30

1 Answers1

2

Of course not even a minute after I post this I had a eureka moment... The fix was simply setting AuthenticationType = "Basic" to the destBaseOptions object.

Feel like a bone head now...

John C
  • 1,761
  • 2
  • 20
  • 30