I want to add a handler mapping (script map) for our custom CGI-Exe to an Internet Information Server using the classes in the Microsoft.Web.Administration namespace. The (simplified) code is:
var serverManager = ServerManager.OpenRemote(serverName);
Configuration webConfig = serverManager.GetWebConfiguration(siteName, appPath);
ConfigurationSection handlersSection = webConfig.GetSection("system.webServer/handlers");
ConfigurationElementCollection handlersCollection = handlersSection.GetCollection();
string elementName = cgiFile + " script map appHost added by ACM";
ConfigurationElement addElement = handlersCollection.CreateElement("add");
addElement["allowPathInfo"] = true;
addElement["modules"] = "CgiModule";
addElement["name"] = elementName;
addElement["path"] = cgiFile;
addElement["requireAccess"] = "Execute";
addElement["scriptProcessor"] = Path.Combine(scriptsPath, cgiFile);
addElement["verb"] = "*";
handlersCollection.Add(addElement);
serverManager.CommitChanges();
This code adds the handler mapping to the mapping list in the IIS, but it is marked as disabled:
I have to manually select “Edit Feature Permissions…” from the Actions pane and select the “Execute” permission in the following dialog:
I want to know how to enable the handler mapping, either by setting different configuration options while creating the handler or by programmatically editing the feature permissions.
Update
I copied the web.config that was created as a result of this script, then I manually added the Execute permission with the dialog above and compared the resulting web.config to the original one:
The start changed from:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
to
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read, Execute, Script">
Now I need to find out, how to set the accessPolicy. But why is this set on the handlers node and not on my specific handler node?