How can I set global mime-types for IIS6 programmatically?

醉酒当歌 提交于 2019-12-07 10:39:06

问题


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"

This seems to work fine when I only need to target W3SVC/1.

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.


回答1:


I think the easier way will be to just amend the mime types on each server, you need only do it once for the change to cascade down to each website, why are you trying to rewrite the .vbs mime type though? you might be better off creating a custom one.

Or you could set the change in the Metabase for IIS, you just need to set the enable direct metabase edit to true on each server then make the changes though code.




回答2:


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)        
}


来源:https://stackoverflow.com/questions/1910658/how-can-i-set-global-mime-types-for-iis6-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!