Compartilhar via


Método ConfigurationSectionWithCollection.Remove

Remove o elemento especificado de uma coleção em uma seção de configuração.

Sintaxe

ConfigurationSectionWithCollection.Remove collectionName, element;  
ConfigurationSectionWithCollection.Remove collectionName, element  

Parâmetros

Nome Definição
collectionName Um valor string que especifica o nome da coleção que tem um elemento a ser removido.
element Um objeto CollectionElement que contém o elemento a ser removido.

Valor de retorno

Esse método não retorna um valor.

Exemplo

O exemplo a seguir exibe os nomes dos manipuladores para o site padrão, remove o elemento manipulador chamado "CGI-exe" se ele estiver presente e, em seguida, lista os nomes do manipulador novamente. O código fará com que o seguinte XML seja adicionado à seção <system.webServer> do arquivo Web.config para o site padrão:

<handlers>

<remove name="CGI-exe" />

</handlers>

' 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 handlers section.  
oSite.GetSection "HandlersSection", oHandlersSection  
  
' Display the current handler names.  
Wscript.Echo "---[Current Handler List]---"  
Call DisplayHandlerNames  
  
' Remove the CGI-exe handler by matching its name.  
For Each oHandler In oHandlersSection.Handlers  
     If oHandler.Name = "CGI-exe" Then  
        oHandlersSection.Remove "Handlers", oHandler  
    End If   
Next  
  
' Refresh the oHandlersSection object so that its contents will  
' reflect the updated configuration.  
oHandlersSection.Refresh_      
  
' List the handler names again to show the change.  
Wscript.Echo "---[New Handler List]---"  
Call DisplayHandlerNames  
  
' Provide a subroutine to display handler names.  
Sub DisplayHandlerNames  
    For Each oHandler In oHandlersSection.Handlers  
        WScript.Echo "Handler Name: " & oHandler.Name  
    Next  
    Wscript.Echo  
End Sub  
  

Observação Chamar o método Remove_ atualiza o repositório de configuração subjacente, mas não o objeto oHandlersSection que está sendo executado na memória. Chamar o método Refresh_ em oHandlersSection garantirá que seus dados sejam precisos se você precisar usá-los posteriormente no mesmo script.

Requisitos

Tipo Descrição
Cliente – IIS 7.0 no Windows Vista
– IIS 7.5 no Windows 7
– IIS 8.0 no Windows 8
– IIS 10.0 no Windows 10
Servidor – IIS 7.0 no Windows Server 2008
– IIS 7.5 no Windows Server 2008 R2
– IIS 8.0 no Windows Server 2012
– IIS 8.5 no Windows Server 2012 R2
– IIS 10.0 no Windows Server 2016
Product – IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0
Arquivo MOF WebAdministration.mof

Confira também

Classe ConfigurationSectionWithCollection
Classe HandlerAction
Classe HandlersSection