共用方式為


ConfigurationSection.RevertToParent 方法

將區段中的組態值還原為其預設值。

語法

ConfigurationSection.RevertToParent();  
ConfigurationSection.RevertToParent(PropertyName);  
ConfigurationSection.RevertToParent  
ConfigurationSection.RevertToParent(PropertyName)  

參數

名稱 定義
PropertyName 選擇性 string 值,其中包含組態區段中的屬性名稱。 屬性可以是巢狀 (例如 。 oLogSection.RevertToParent("CentralBinaryLogFile.Directory")

傳回值

這個方法不會傳回值。

備註

這個方法提供刪除已寫入組態檔的組態值的方法。

範例

下列範例示範使用 RevertToParent 方法的兩種方式:

  1. 第一個部分會將指定的屬性還原為預設值。 下列範例中的這一行會將 Enabled 屬性名稱指定為 RevertToParent 參數,以還原預設網站的 屬性 DefaultDocumentSection

    oDefaultDocumentSection.RevertToParent("Enabled")  
    

    這會移除 在預設網站的Web.config檔案中指定的 值 false ,並將它取代為 預設值 true

  2. 第二個部分會將整個區段還原為預設值。 下列範例中的這一行會藉由指定 沒有 的參數 RevertToParent 來還原預設網站的整個 DefaultDocumentSection 內容。

    oDefaultDocumentSection.RevertToParent  
    

    這會從預設網站之Web.config檔案中的預設檔區段移除所有值。 預設網站的預設值會取代移除的值。

' Connect to the WMI WebAdministration namespace.  
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")  
  
' Get the DefaultDocumentSection for the Default Web Site.  
Set oSite=oWebAdmin.Get("Site.Name='Default Web Site'")  
oSite.GetSection "DefaultDocumentSection", oDefaultDocumentSection  
  
' 1. Revert the Enabled property to its default value.  
oDefaultDocumentSection.RevertToParent("Enabled")  
  
' 2. Revert the entire default document section.  
oDefaultDocumentSection.RevertToParent  
  

規格需求

類型 描述
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

另請參閱

ConfigurationSection 類別
ConfigurationSectionWithCollection 類別
ConfiguredObject 類別
DefaultDocumentSection 類別