添加ISAPI筛选器添加到现有站点Microsoft.Web.Administration [英] Add an ISAPI Filter to an existing Site with Microsoft.Web.Administration
问题描述
我想添加/配置到C#ISAPI筛选器和Microsoft.Web.Administration组装。到目前为止,我没能添加一个ISAPI筛选器为一个单一的网站。
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.
我刚刚发现本条(http://www.iis.net/ConfigReference/ system.webServer / isapiFilters)在整个IIS中的全局设置添加。我只需要为特定网站。我使用的是IIS 7.5。
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.
推荐答案
您只需要调整给出的例子(见内嵌注释):
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();
如果您不知道该网站的名字,但知道该网站的ID(或IIS数),那么你可以通过执行查询的名称:
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;
这篇关于添加ISAPI筛选器添加到现有站点Microsoft.Web.Administration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!