[英]Automating IIS7 Website creation using impersonation (with Microsoft.Web.Administration)
[英]How do I manipulate Handler Mappings cleanly in IIS7 using the Microsoft.Web.Administration namespace?
使用Microsoft.Web.Administration
命名空間操作Handler Mappings時,有沒有辦法在站點級別刪除<remove name="handler name">
。
例如,我有一個站點,它繼承了全局處理程序映射配置中的所有處理程序映射。 在applicationHost.config
, <location>
標簽最初看起來像這樣:
<location path="60030 - testsite-60030.com">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication userName="" />
</authentication>
</security>
</system.webServer>
</location>
要刪除處理程序,我使用類似的代碼:
string siteName = "60030 - testsite-60030.com";
string handlerToRemove = "ASPClassic";
using(ServerManager sm = new ServerManager())
{
Configuration siteConfig =
serverManager.GetApplicationHostConfiguration();
ConfigurationSection handlersSection =
siteConfig.GetSection("system.webServer/handlers", siteName);
ConfigurationElementCollection handlersCollection =
handlersSection.GetCollection();
ConfigurationElement handlerElement = handlersCollection
.Where(h => h["name"].Equals(handlerMapping.Name)).Single();
handlersCollection.Remove(handlerElement);
}
這導致網站的<location>
標記看起來像:
<location path="60030 - testsite-60030.com">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication userName="" />
</authentication>
</security>
<handlers>
<remove name="ASPClassic" />
</handlers>
</system.webServer>
</location>
到現在為止還挺好。 但是,如果我重新添加ASPClassic
處理程序, ASPClassic
導致:
<location path="60030 - testsite-60030.com">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication userName="" />
</authentication>
</security>
<handlers>
<remove name="ASPClassic" />
<add name="ASPClassic" path="*.asp" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="%windir%\system32\inetsrv\asp.dll" resourceType="File" />
</handlers>
</system.webServer>
</location>
對於每個刪除了處理程序然后以編程方式重新添加的網站,這可能會導致很多問題。 有沒有辦法只使用Microsoft.Web.Administration命名空間代碼刪除<remove name="ASPClassic" />
?
我已經與IIS產品團隊討論過這個問題,這似乎是配置系統的一個錯誤。 更有趣的是,當我使用IIS 7.5在Win7上嘗試此代碼時,我甚至無法以編程方式重新添加處理程序。 嘗試這樣做會導致COM異常,指出:
“錯誤:無法添加類型為'add'的重復集合條目,並將唯一鍵屬性'name'設置為'ASPClassic'”
這變得更加成問題,因為一旦用戶“刪除”某個位置的處理程序,在修復此錯誤之前,無法通過MWA API重新添加該位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.