allowDefinition設定組態區段的屬性。
語法
ConfigurationSection.SetAllowDefinition(AllowDefinition)
ConfigurationSection.SetAllowDefinition(AllowDefinition);
參數
| 名稱 | 定義 |
|---|---|
AllowDefinition |
變數 string ,指定要設定屬性的值 allowDefinition 。 後續的一節會列出可能的屬性值。 |
傳回值
這個方法不會傳回值。
備註
allowDefinition 屬性會指定可在組態階層值中設定指定組態區段的位置。 這些屬性是在 ApplicationHost.config 檔案的 區段中指定 <configSections> 。
因為 SetAllowDefinition 是靜態方法,所以您應該藉由取得類別物件來呼叫它,如下列範例所示。
' Correct syntax:
Set oAnonAuth = oWebAdmin.Get("AnonymousAuthenticationSection")
oAnonAuth.SetAllowDefinition "MachineOnly"
下列語法失敗,因為它嘗試在 類別的 Site 具象實例上呼叫 SetAllowDefinition 。 呼叫 方法會導致 「SWbemObjectEx: 找不到」 錯誤。
' Incorrect syntax:
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")
oSite.GetSection "AnonymousAuthenticationSection", oAnonAuth
oAnonAuth.SetAllowDefinition "MachineOnly"
下表列出屬性的可能值 allowDefinition 。
| 關鍵字 | 描述 |
|---|---|
Everywhere |
區段可以在階層中的任何位置設定。 |
MachineOnly |
區段只能在Machine.config檔案中設定。 注意:Machine.config檔案的預設位置是%systemroot% Microsoft.NET\Framework\version > \ <config\。 |
MachineToWebRoot |
區段只能在Machine.config檔案或根Web.config檔案中設定。 注意:根Web.config檔案的預設位置是%systemroot% Microsoft.NET\Framework\version > \ <config\。 |
AppHostOnly |
區段只能在ApplicationHost.config檔案中設定。 |
MachineToApplication |
區段只能在全域層級設定。 針對.NET Framework區段,全域層級是根Web.config或Machine.config檔案;對於 IIS 區段,它是ApplicationHost.config檔案;而對於應用程式,則是根應用程式的Web.config檔案。 |
範例
下列範例會 allowDefinition 設定匿名驗證組態區段的屬性。
' Get the WebAdministration namespace.
Set oWebAdmin = GetObject( _
"winmgmts:root\WebAdministration")
' Get the AnonymousAuthenticationSection.
Set oAnonAuth = oWebAdmin.Get( _
"AnonymousAuthenticationSection")
' Set the AllowDefinition attribute.
oAnonAuth.SetAllowDefinition "MachineToApplication"
規格需求
| 類型 | 描述 |
|---|---|
| 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 |
另請參閱
AnonymousAuthenticationSection 類別
ConfigurationSection 類別
ConfigurationSection.GetAllowDefinition 方法