无法创建Azure WebSpace

时间:2015-05-01 00:26:59

标签: c# azure azure-web-sites azure-management

我正在尝试使用nuget包Microsoft.WindowsAzure.Management.WebSites (Version 3.0.0)

创建一个新网站

本教程很有帮助(即使它的Java): http://azure.microsoft.com/fi-fi/documentation/articles/java-create-azure-website-using-java-sdk/ 除了它建议使用WebSpaceNames.WestUSWebSpace常数。

var hostingPlanParams = new WebHostingPlanCreateParameters
{
    Name = this.webhostingPlanName,
    NumberOfWorkers = 1,
    SKU = SkuOptions.Free,
    WorkerSize = WorkerSizeOptions.Small
};
var result = new WebSiteManagementClient(this.Credentials)
    .WebHostingPlans
    .CreateAsync(WebSpaceNames.WestUSWebSpace, hostingPlanParams, CancellationToken.None)
    .Result

这将导致异常:NotFound: Cannot find WebSpace with name westuswebspace.

我实际上想要创建一个自定义WebSpace。

除了我找不到任何方法。 See MSDN

因此,我能够完成这项工作的唯一方法是使用通过manage.windowsazure.com站点创建的现有WebSpace。这无法实现自动化的全部目的。

IWebSpaceOperations上的唯一创建[...]方法是CreatePublishingUserAsync,我也尝试过运行它,但它会导致异常This operation is not supported for subscriptions that have co-admins.这本身很烦人,对我来说没有多大意义,但这不是我问题的核心。

1 个答案:

答案 0 :(得分:0)

我使用预发布包解决了这个问题:// Create Web Hosting Plan var hostingPlanParams = new WebHostingPlanCreateOrUpdateParameters { WebHostingPlan = new WebHostingPlan() { Name = "WebHostingPlanName", Location = "Australia Southeast", Properties = new WebHostingPlanProperties { NumberOfWorkers = 1, Sku = SkuOptions.Standard, WorkerSize = WorkerSizeOptions.Small } }, }; var result = this.ManagementContext.WebSiteManagementClient.WebHostingPlans.CreateOrUpdateAsync( "ResourceGroupName", "WebHostingPlanName", CancellationToken.None).Result; // Create Website var websiteParams = new WebSiteCreateOrUpdateParameters { WebSite = new WebSiteBase { Location = "Australia Southeast", Name = "WebSiteName", Properties = new WebSiteBaseProperties { ServerFarm = "WebHostingPlanName" } } }; var siteResult = this.ManagementContext.WebSiteManagementClient.WebSites.CreateOrUpdateAsync( "ResourceGroupName", "WebSiteName", null, websiteParams, CancellationToken.None).Result; 哪个效果很好。除了它只是事先预发布

$controllerClass = get_class($this);
$moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
$tmp = substr($controllerClass, strrpos($controllerClass, '\\')+1 );
$controllerName = str_replace('Controller', "", $tmp);

//set 'variable' into layout...
$this->layout()->currentModuleName      = strtolower($moduleNamespace);
$this->layout()->currentControllerName  = strtolower($controllerName);
$this->layout()->currentActionName      = $this->params('action');

如果您想使用部署插槽,则必须考虑以下因素: https://github.com/Azure/azure-sdk-for-net/issues/1088