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