Modify ISAPI and CGI extensions

c#, cgi, iis, isapi

Solution

I found a solution. I changed the code like below. and it worked.

private void buttonOK_Click(object sender, EventArgs e)
   {

        using (ServerManager serverManager = new ServerManager())
        {
            Configuration config = serverManager.GetApplicationHostConfiguration();
            ConfigurationSection isapiCgiRestrictionSection = config.GetSection("system.webServer/security/isapiCgiRestriction");
            ConfigurationElementCollection isapiCgiRestrictionCollection = isapiCgiRestrictionSection.GetCollection();
            foreach (ConfigurationElement element in isapiCgiRestrictionCollection)
            {
                element.SetAttributeValue("allowed", false);
            }

            ConfigurationElement addElement = isapiCgiRestrictionCollection.CreateElement("add");

            serverManager.CommitChanges();          
        }
    }

Problem

I have a problem with IIS server, How can I modify ISAPI elements with using C# language? Forexample : ASP.net V4.0 restriction is "Not Allowed". And I want to set as "Allowed" like below picture. I can add an elements with this Code. But I cant modify. ``` using System; using System.Text; using Microsoft.Web.Administration; internal static class Sample { private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection isapiFiltersSection = config.GetSection("system.webServer/isapiFilters"); 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(); } } } ``` Thanks For your advice.

Original source