如何使用脚本在 IIS 7 中添加新网站?

Aar*_*paa 4 scripting iis

我希望能够从命令行创建一个带有新主机标头的新网站(显然我可以使用 IIS Manager做到这一点),以便可以编写脚本。

基本上你可以在 IIS 6 上使用iisweb做什么。

Osk*_*orn 6

使用内置appcmd,像这样 - 使用 bindings 参数可以指定主机头:

appcmd add site /name:contoso /id:2 /physicalPath:c:\contoso /bindings:http/*:80: marketing.contoso.com
Run Code Online (Sandbox Code Playgroud)

变量 name string 是名称,变量 id uint 是要分配给站点的无符号整数。在 Appcmd.exe 中添加站点时,变量 name string 和 id uint 是唯一需要的变量。变量绑定字符串包含用于访问站点的信息,它应该采用协议/IP_address:port:host_header 的形式。

  • 我发现很方便的一件事是在一次调用中添加多个绑定。为此,请将每个绑定用引号括起来并用逗号分隔它们:`appcmd add site /name:contoso /bindings:"http/*:80:","https/*:443:" /physicalPath:C:\contoso `. 否则,您必须为每个单独调用:`appcmd set site /site.name:"G4" /+bindings.[protocol='https',bindingInformation='*:443:']`。 (8认同)