將專案加入至組態區段中的集合。
語法
ConfigurationSectionWithCollection.Add collectionName, element;
ConfigurationSectionWithCollection.Add collectionName, element
參數
| 名稱 | 定義 |
|---|---|
collectionName |
string值,其中包含將加入的集合名稱。 |
element |
要加入專案的 CollectionElement 物件。 |
傳回值
這個方法不會傳回值。
備註
當您使用 方法時 Add ,會自動儲存您所做的變更。 您不需要使用 Put_ 方法。
範例
下列範例會將 MIME 對應新增至預設網站。
' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Get the default Web site.
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")
' Get the static content section by using the GetSection method.
oSite.GetSection "StaticContentSection", oStaticContentSection
' Get the MimeMapElement class object.
Set oMimeMapElement = oWebAdmin.Get("MimeMapElement")
' Spawn a new instance of the MimeMapElement class.
Set oNewMimeMap = oMimeMapElement.SpawnInstance_
' Assign values to the FileExtension and MimeType properties.
oNewMimeMap.FileExtension = "MyFileExtension"
oNewMimeMap.MimeType = "application/MyApp"
' Add the MIME map to the collection.
oStaticContentSection.Add "StaticContent", oNewMimeMap
規格需求
| 類型 | 描述 |
|---|---|
| Client | - Windows Vista 上的 IIS 7.0 - Windows 7 上的 IIS 7.5 - Windows 8 上的 IIS 8.0 - Windows 10上的 IIS 10.0 |
| 伺服器 | - Windows Server 2008 上的 IIS 7.0 - Windows Server 2008 R2 上的 IIS 7.5 - Windows Server 2012 上的 IIS 8.0 - Windows Server 2012 R2 上的 IIS 8.5 - Windows Server 2016上的 IIS 10.0 |
| 產品 | - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0 |
| MOF 檔案 | WebAdministration.mof |
另請參閱
CollectionElement 類別
ConfigurationSectionWithCollection 類別
MimeMapElement 類別