Compartilhar via


Enabling ISAPI Filters Using ADSI

To enable ISAPI filters, they must be installed on the IIS server and registered with IIS. ISAPI filters are registered at the Web service level or the Web site level. The IIS ADSI and WMI providers contain a set of methods that allow applications to register ISAPI filters by creating an IIsFilters object, and then populating it with IIsFilter objects for each filter.

A Filters object is automatically created for the Web service when IIS is installed. For an individual Web site, however, you may need to create this object yourself before you can proceed.

The following example shows you how to use the VBScript scripting language to add an ISAPI filter to the IIsFilters object at the Web service level.

First, the filter name is added to the filter load order using the IIsFilters object. Once you gain access to the parent IIsFilters container object, you can create a new IIsFilter object and set its properties to register the new filter.

Dim FiltersObj 
Dim FilterObj 
Dim LoadOrder 
Dim FilterName 
Dim FilterPath 
Dim FilterDesc 

FilterName = "myFilter" 
FilterPath = "C:\iisfilts\myfilter.dll" 
FilterDesc = "This is my filter" 

Set FiltersObj = GetObject("IIS://LocalHost/W3SVC/Filters") 
LoadOrder = FiltersObj.FilterLoadOrder 
If LoadOrder <> "" Then 
  LoadOrder = LoadOrder & "," 
End If 
LoadOrder = LoadOrder & FilterName 
FiltersObj.FilterLoadOrder = LoadOrder 
FiltersObj.SetInfo 

Set FilterObj = FiltersObj.Create("IIsFilter", FilterName) 
FilterObj.FilterPath = FilterPath 
FilterObj.FilterDescription = FilterDesc 
FilterObj.SetInfo