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

一个人想着一个人 提交于 2019-12-05 16:29:47

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.

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