我正在寻找一种使用 Microsoft.Web.Administration.dll 在 IIS 7 中添加处理程序映射的方法。有没有可以在 ServerManager 对象上使用的方法?
这些是通过 GUI 添加时要遵循的步骤,但同样,我需要以编程方式完成此操作。http://coderock.net/how-to-create-a-handler-mapping-for-an-asp-net-iis-7-with-application-running-in-integrated-mode/
这是我用来启用 ISAPI 限制的代码,处理程序映射是否有类似的东西?
public override void AddIsapiAndCgiRestriction(string description, string path, bool isAllowed)
{
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection isapiCgiRestrictionSection = config.GetSection("system.webServer/security/isapiCgiRestriction");
ConfigurationElementCollection isapiCgiRestrictionCollection = isapiCgiRestrictionSection.GetCollection();
ConfigurationElement addElement = isapiCgiRestrictionCollection.CreateElement("add");
addElement["path"] = path;
addElement["allowed"] = isAllowed;
addElement["description"] = description;
isapiCgiRestrictionCollection.Add(addElement);
serverManager.CommitChanges();
}
}