问题描述
问候,
Greetings, 我想通过C#将ISAPI筛选器添加到IIS,例如php的isapi.以下部分是我的代码示例,但是我无法使其按预期运行,有什么主意吗? I want to add an ISAPI filter into IIS by C#, for example the isapi for php. The following part is my code sample, but I couldn't make it works as it supposed to be, any idea? 字符串
string FilterName = "myFilter";
字符串 FilterPath = @"C:\ iisfilts \ myfilter.dll" ;
string FilterPath = @"C:\iisfilts\myfilter.dll";
字符串 FilterDesc = 这是我的过滤器" ;
string FilterDesc = "This is my filter";
DirectoryEntry FiltersObj = 新 DirectoryEntry ( "IIS://LocalHost/W3SVC/Filters" );
DirectoryEntry FiltersObj = new DirectoryEntry("IIS://LocalHost/W3SVC/Filters");
字符串 LoadOrder = FiltersObj.InvokeGet( "FilterLoadOrder " ).ToString();
string LoadOrder = FiltersObj.InvokeGet("FilterLoadOrder").ToString();
如果 (LoadOrder!= null )
if (LoadOrder != null)
LoadOrder = LoadOrder + ," ;
LoadOrder = LoadOrder + ",";
LoadOrder = LoadOrder + FilterName;
LoadOrder = LoadOrder + FilterName;
FiltersObj.InvokeSet( "FilterLoadOrder" , 新 对象 [] {LoadOrder});
FiltersObj.InvokeSet("FilterLoadOrder", new Object[] {LoadOrder});
FiltersObj.Invoke( "SetInfo" , null );
FiltersObj.Invoke("SetInfo", null);
DirectoryEntry FilterObj =( DirectoryEntry )FiltersObj.Invoke( 创建" , 新 对象 [] { "IIsFilter" ,FilterName});
DirectoryEntry FilterObj = (DirectoryEntry)FiltersObj.Invoke("Create", new Object[] { "IIsFilter", FilterName });
FilterObj.Properties [ "FilterPath" ].Value = FilterPath;
FilterObj.Properties["FilterPath"].Value = FilterPath;
FilterObj.Properties [ "FilterDescription" ].Value = FilterDesc;
FilterObj.Properties["FilterDescription"].Value = FilterDesc;
FilterObj.Invoke( "SetInfo" , null );
FilterObj.Invoke("SetInfo", null);
推荐答案
{
公共 无效 添加( 字符串 FilterName, 字符串 FilterPath)
public void add(string FilterName, string FilterPath)
{
DirectoryEntry FiltersObj = 新 DirectoryEntry ( " IIS://LocalHost/W3SVC/1/Filters" );
DirectoryEntry FiltersObj = new DirectoryEntry("IIS://LocalHost/W3SVC/1/Filters");
字符串 LoadOrder = FiltersObj.InvokeGet( " FilterLoadOrder" ).ToString();
string LoadOrder = FiltersObj.InvokeGet("FilterLoadOrder").ToString();
如果 (LoadOrder!= null )
if (LoadOrder != null)
LoadOrder = LoadOrder + "," ;
LoadOrder = LoadOrder + ",";
LoadOrder = LoadOrder + FilterName;
LoadOrder = LoadOrder + FilterName;
FiltersObj.InvokeSet( " FilterLoadOrder' , 新建 对象 [] {LoadOrder});
FiltersObj.InvokeSet("FilterLoadOrder", new Object[] { LoadOrder });
FiltersObj.Invoke( " SetInfo'; , null );
FiltersObj.Invoke("SetInfo", null);
DirectoryEntry FilterObj =( DirectoryEntry )FiltersObj.Invoke( &; Create"; , 新 对象 [] { " IIsFilter" ,FilterName});
DirectoryEntry FilterObj = (DirectoryEntry)FiltersObj.Invoke("Create", new Object[] { "IIsFilter", FilterName });
FilterObj.Properties [ "FilterPath" ].Value = FilterPath;
FilterObj.Properties["FilterPath"].Value = FilterPath;
FilterObj.Invoke( " SetInfo'; , null );
FilterObj.Invoke("SetInfo", null);
}
}
您唯一的错误是在"iis://localhost/w3svc/1/filters"中遗漏了1;
Your only mistake was leaving out the 1 in "iis://localhost/w3svc/1/filters"
这篇关于如何启用ISAPI筛选器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!