WebDeploy到Azure失败

时间:2014-04-18 04:23:34

标签: azure webdeploy azure-web-sites microsoft-web-deploy

我使用以下代码通过WebDeploy部署到Azure网站。我可以使用相同的服务器和凭据信息使用Visual Studio 2013将WebDeploy部署到同一站点,但是当我运行下面的代码时,它会一直失败并告诉我它无法授权,它会获得401.任何想法方式?

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

}

1 个答案:

答案 0 :(得分:2)

当然,在发布此消息后的一分钟内,我有一个尤里卡时刻......修复只是设置AuthenticationType =" Basic"到destBaseOptions对象。

现在感觉像是一个骨头......