如何以编程方式为IIS6设置全局mime类型? [英] How can I set global mime-types for IIS6 programmatically?
问题描述
目前,我可以使用以下语法为adsl.vbs设置IIS6上主要网站的mime类型:
Currently I am able to to set a mime type with adsutil.vbs for the primary web site on IIS6 with the following syntax:
cscript adsutil.vbs set W3SVC/1/Root/MimeMap ".manifest, text/cache-manifest"
当我只需要定位W3SVC/1时,这似乎很好用.
This seems to work fine when I only need to target W3SVC/1.
我需要编写一个更新脚本,以确保给定IIS6安装上的所有站点都配置了正确的mime类型.我可以将mime类型添加到每个个人站点,也可以在全局级别添加.我需要以编程方式进行此操作,并尽可能使用adsutil.vbs.
I need to write an update script that will make sure that any sites on a given IIS6 installation have the proper mime type configured. I could either add the mime type to each individial site or at the global level. I need to do this programmatically and would like to use adsutil.vbs if at all possible.
推荐答案
您可以使用ADSI和powershell 2.0.
You could use ADSI and powershell 2.0.
$adsiPrefix = "IIS://$serverName"
$iisPath = "W3SVC"
$iisADSI = [ADSI]"$adsiPrefix/$iisPath"
$site = $iisADSI.Create("IISWebServer", $script:webSiteNumber)
$xapMimeType = New-Object -comObject MimeMap
SetCOMProperty $xapMimeType "Extension" ".xap"
SetCOMProperty $xapMimeType "MimeType" "application/x-silverlight-app"
$site.Properties["MimeMap"].Add($xapMimeType)
$site.SetInfo()
$site.CommitChanges()
function SetCOMProperty($target, $member, $value) {
$target.psbase.GetType().InvokeMember($member, [System.Reflection.BindingFlags]::SetProperty, $null, $target, $value)
}
这篇关于如何以编程方式为IIS6设置全局mime类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!