Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么IIS ServerManager类创建我的处理程序映射被禁用?_C#_Iis_Iis 7_Servermanager - Fatal编程技术网

C# 为什么IIS ServerManager类创建我的处理程序映射被禁用?

C# 为什么IIS ServerManager类创建我的处理程序映射被禁用?,c#,iis,iis-7,servermanager,C#,Iis,Iis 7,Servermanager,我想使用Microsoft.Web.Administration命名空间中的类将自定义CGI Exe的处理程序映射(脚本映射)添加到Internet信息服务器。 (简化)代码为: var serverManager=serverManager.OpenRemote(serverName); 配置webConfig=serverManager.GetWebConfiguration(站点名称、应用路径); ConfigurationSection handlersSection=webConfig

我想使用Microsoft.Web.Administration命名空间中的类将自定义CGI Exe的处理程序映射(脚本映射)添加到Internet信息服务器。 (简化)代码为:

var serverManager=serverManager.OpenRemote(serverName);
配置webConfig=serverManager.GetWebConfiguration(站点名称、应用路径);
ConfigurationSection handlersSection=webConfig.GetSection(“system.webServer/handlers”);
ConfigurationElementCollection handlersCollection=handlersSection.GetCollection();
string elementName=cgiFile+“脚本映射由ACM添加的appHost”;
ConfigurationElement addElement=handlersCollection.CreateElement(“添加”);
addElement[“allowPathInfo”]=true;
addElement[“模块”]=“CgiModule”;
addElement[“name”]=elementName;
addElement[“路径”]=cgiFile;
addElement[“RequiredAccess”]=“执行”;
addElement[“scriptProcessor”]=Path.Combine(scriptsPath,cgiFile);
加法[“动词”]=“*”;
handlersCollection.Add(addElement);
serverManager.CommitChanges();
此代码将处理程序映射添加到IIS中的映射列表中,但标记为禁用:

我必须从操作窗格中手动选择“编辑功能权限…”,然后在以下对话框中选择“执行”权限:

我想知道如何启用处理程序映射,可以通过在创建处理程序时设置不同的配置选项,也可以通过编程方式编辑功能权限

更新

我复制了根据此脚本创建的web.config,然后使用上面的对话框手动添加了执行权限,并将生成的web.config与原始web.config进行了比较:

开始更改为:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>



现在我需要了解如何设置accessPolicy。但是为什么在handlers节点上设置了这个,而不是在我的特定handler节点上呢?

有时候,它有助于解释关于stackoverflow的问题。在玩了两天之后,我在发布问题几个小时后找到了解决方案:

我需要为处理程序设置accessPolicy

添加这一行后,它终于起作用了:

handlersSection["accessPolicy"] = "Read, Script, Execute";
似乎我只是使用了错误的搜索词,我寻找的是“编辑功能权限”,而不是accessPolicy。

从任何“上传”文件夹中删除“执行”访问权限,以避免通过上传ASPX页面进行黑客攻击。
handlersSection["accessPolicy"] = "Read, Script, Execute";