Поделиться через


Метод ConfigurationSectionWithCollection.Remove

Удаляет указанный элемент из коллекции в разделе конфигурации.

Синтаксис

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

Параметры

Имя Определение
collectionName Значение string типа , указывающее имя коллекции с удаляемым элементом.
element Объект CollectionElement , содержащий удаляемый элемент.

Возвращаемое значение

Этот метод не возвращает значение.

Пример

В следующем примере отображаются имена обработчиков для веб-сайта по умолчанию, удаляется элемент handler с именем "CGI-exe", если он присутствует, а затем снова выводится список имен обработчиков. Код приведет к добавлению следующего XML-кода в <system.webServer> раздел файла Web.config для веб-сайта по умолчанию:

<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  
  

ПримечаниеRemove_ Вызов метода обновляет базовое хранилище конфигураций, но не oHandlersSection объект, выполняющийся в памяти. Вызов метода в Refresh_oHandlersSection обеспечит точность его данных, если вам потребуется использовать их позже в том же скрипте.

Требования

Тип Описание
клиент — IIS 7.0 в Windows Vista
— IIS 7.5 в Windows 7
— IIS 8.0 в Windows 8
— IIS 10.0 в Windows 10
Сервер — IIS 7.0 в Windows Server 2008
— IIS 7.5 в Windows Server 2008 R2
— IIS 8.0 в Windows Server 2012
— IIS 8.5 в Windows Server 2012 R2
— IIS 10.0 в Windows Server 2016
Продукт — IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0
MOF-файл WebAdministration.mof

См. также:

Класс ConfigurationSectionWithCollection
Класс HandlerAction
Класс HandlersSection