如何通过脚本自动创建IIS网站

时间:2016-06-06 06:45:54

标签: powershell azure iis dns

我们有一个MVC5 C#网站,允许客户购买域名。 购买后,我们希望在IIS中自动创建网站,以便任何对它的调用(比如它的名为www.test.com)都会显示一个新的模板化网站。

最好的方法是什么?最好是为PowerShell编写脚本吗?

有人知道Azure中需要的脚本吗?

2 个答案:

答案 0 :(得分:0)

您可以选择c#PowerShell来创建网站。

对于PowerShell,请使用WebAdministration moduleNew-Website cmdlet。对于Azure网站,请使用Azure Resource Manager

答案 1 :(得分:0)

要自动创建Azure网站,您可以在C#中使用PowerShell或Azure Management Librairies

以下是使用Powershell创建Azure网站的脚本:

$rgName = 'example-RG';
$location = 'West Europe';
$servicePlanName = 'example-SP';
$siteName = 'exampleWebsite Name';

Login-AzureRmAccount

#Create the resource Group
New-AzureRmResourceGroup -Name $rgName -Location $location

#Create the service plan
New-AzureRmAppServicePlan -ResourceGroupName $rgName -Location $location -  Name $servicePlanName -Tier Free

#Create the web app
New-AzureRmWebApp -ResourceGroupName $rgName -Location $location -Name $siteName -AppServicePlan $servicePlanName