本文介绍了修改ISAPI和CGI扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有IIS服务器,
如何修改ISAPI元素使用C#语言?
How can I modify ISAPI elements with using C# language?
Forexample:ASP.net V4.0限制不允许。我想将其设置为允许像下面的图片。
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.
推荐答案
我找到了解决办法。我改变了代码如下图所示。和它的工作。
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();
}
}
这篇关于修改ISAPI和CGI扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!