3
我正在尋找一種方法來使用Microsoft.Web.Administration.dll在IIS 7中添加處理程序映射。有沒有我可以在ServerManager對象上使用的方法?如何以編程方式添加IIS處理程序映射
這些是通過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();
}
}