Reputation: 27937
I'm trying to add/configure an ISAPI Filter through c# and the Microsoft.Web.Administration assembly. So far I didn't manage to add an an ISAPI Filter for a single Web Site.
I just found this Article (http://www.iis.net/ConfigReference/system.webServer/isapiFilters) for adding it in the global setting for the whole IIS. I just need it for a specific site. I'm using IIS 7.5.
Upvotes: 3
Views: 1460
Reputation: 119846
You just need to tweak the example given (see the inline comments):
ServerManager serverManager = new ServerManager();
Configuration config = serverManager.GetApplicationHostConfiguration();
// Change this line:
ConfigurationSection isapiFiltersSection =
config.GetSection("system.webServer/isapiFilters");
// To this by adding an extra param specifying the site name:
ConfigurationSection isapiFiltersSection =
config.GetSection("system.webServer/isapiFilters", "my site name");
ConfigurationElementCollection isapiFiltersCollection =
isapiFiltersSection.GetCollection();
ConfigurationElement filterElement =
isapiFiltersCollection.CreateElement("filter");
filterElement["name"] = @"SalesQueryIsapi";
filterElement["path"] = @"c:\Inetpub\www.contoso.com\filters\SalesQueryIsapi.dll";
filterElement["enabled"] = true;
filterElement["enableCache"] = true;
isapiFiltersCollection.Add(filterElement);
serverManager.CommitChanges();
If you don't know the site name but know the site ID (or IIS number) then you can query the name by doing:
int iisNumber = 12345;
string siteName = serverManager.Sites.Single(s => s.Id == iisNumber).Name;
Upvotes: 2