使用Microsoft.Web.Administration
名稱空間處理處理程序映射時,是否有辦法在站點級別刪除<remove name="handler name">
。如何在IIS7中使用Microsoft.Web.Administration命名空間乾淨地處理Handler映射?
例如,我有一個站點從全局處理程序映射配置繼承所有處理程序映射。在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
處理這個結果:
<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" />
?
感謝Tobin的迴應,現在我知道我不是唯一對此感到挑剔的人。是否值得在Microsoft Connect上打開一個問題? – Kev 2009-11-06 03:01:17
是的。我會說,繼續打開它。該團隊已經意識到這一點,但將Connect用於追蹤非常值得。 – tobint 2009-11-06 08:24:19
@Kev, 嗨,我也試圖做一些類似的事情,試圖從使用WMI的IIS7中的網站中刪除處理程序映射。該代碼似乎工作正常,但處理程序映射從不刪除。因爲我可以在移除後看到它的inetmgr。請檢查此:http://stackoverflow.com/questions/7102056/how-to-remove-handler-mapping-from-a-website-in-iis7-using-wmi-and-c-vb-net – 2011-08-18 03:31:11