首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> ASP.NET 基礎 >> 關於ASP.NET

使用 IIS 7.0 PowerShell 建立網站、應用程式、虛擬目錄與應用程式集區

     編輯:關於ASP.NET

簡介

IIS 7.0 引入 PowerShell 管理模組,提供 Web-Sites、Apps、Virtual Directories、Application Pools 等命名空間。內建的 Cmdlet 讓建立與管理這些項目變得直觀易懂。

建立網站

在 PowerShell 中,New-Item 常用於建立新項目。例如在檔案系統中 New-Item c:\TestDirectory 會建立資料夾。在 IIS 命名空間下,同樣使用 New-Item 建立網站,但需額外指定 -bindings 參數。

範例指令

PS IIS:\Sites> New-Item iis:\Sites\TestSite -bindings @{protocol="http";bindingInformation=":80:TestSite"} -physicalPath c:\test
PS IIS:\Sites> dir
Name                ID State Physical Path      Bindings
----                -- ----- -------------      --------
Default Web Site    1  Started f:\inetpub\wwwroot http *:80:
TestSite            2  Started c:\test          http :80:TestSite

Bindings 參數解析

-bindings 使用 Hash Table(雜湊表)表示,鍵值對對應 IIS 設定檔中 <binding> 元素的屬性:

<bindings>
  <binding protocol="http" bindingInformation=":80:TestSite" />
</bindings>

Hash Table 提供彈性,未來若 <binding> 擴充新屬性,同樣可透過鍵值對支援。

建立應用程式、虛擬目錄與應用程式集區

同樣使用 New-Item,路徑分別為 iis:\Sites\SiteName\AppName、iis:\Sites\SiteName\VirtualDir、iis:\AppPools\PoolName。參數如 -physicalPath、-applicationPool 等視情況指定。

總結

PowerShell 讓 IIS 7.0 的自動化部署與管理更具腳本化優勢,適合 CI/CD 流程與批次作業。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved