必须注册几种 MIME 类型和文件扩展名,客户端系统上的浏览器才能加载正确的处理程序。需要添加以下类型:
扩展名 | MIME 类型 |
|---|
.manifest | application/manifest |
.xaml | application/xaml+xml |
.application | application/x-ms-application |
.xbap | application/x-ms-xbap |
.deploy | application/octet-stream |
.xps | application/vnd.ms-xpsdocument |
说明: |
|---|
您不需要在客户端系统上注册 MIME 类型或文件扩展名。它们是在您安装 Microsoft .NET Framework时自动注册的。 |
下面的 Microsoft Visual Basic Scripting Edition (VBScript) 示例自动将必要的 MIME 类型添加到 IIS。若要使用此脚本,请将代码复制到服务器上的 .vbs 文件。然后,通过从命令行运行此文件或者在 Microsoft Windows 资源管理器中双击此文件来运行脚本。
' This script adds the necessary Windows Presentation Foundation MIME types
' to an IIS Server.
' To use this script, just double-click or execute it from a command line.
' Running this script multiple times results in multiple entries in the IIS MimeMap.
Dim MimeMapObj, MimeMapArray, MimeTypesToAddArray, WshShell, oExec
Const ADS_PROPERTY_UPDATE = 2
' Set the MIME types to be added
MimeTypesToAddArray = Array(".manifest", "application/manifest", ".xaml", _
"application/xaml+xml", ".application", "application/x-ms-application", _
".deploy", "application/octet-stream", ".xbap", "application/x-ms-xbap", _
".xps", "application/vnd.ms-xpsdocument")
' Get the mimemap object
Set MimeMapObj = GetObject("IIS://LocalHost/MimeMap")
' Call AddMimeType for every pair of extension/MIME type
For counter = 0 to UBound(MimeTypesToAddArray) Step 2
AddMimeType MimeTypesToAddArray(counter), MimeTypesToAddArray(counter+1)
Next
' Create a Shell object
Set WshShell = CreateObject("WScript.Shell")
' Stop and Start the IIS Service
Set oExec = WshShell.Exec("net stop w3svc")
Do While oExec.Status = 0
WScript.Sleep 100
Loop
Set oExec = WshShell.Exec("net start w3svc")
Do While oExec.Status = 0
WScript.Sleep 100
Loop
Set oExec = Nothing
' Report status to user
WScript.Echo "Windows Presentation Foundation MIME types have been registered."
' AddMimeType Sub
Sub AddMimeType (Ext, MType)
' Get the mappings from the MimeMap property.
MimeMapArray = MimeMapObj.GetEx("MimeMap")
' Add a new mapping.
i = UBound(MimeMapArray) + 1
Redim Preserve MimeMapArray(i)
Set MimeMapArray(i) = CreateObject("MimeMap")
MimeMapArray(i).Extension = Ext
MimeMapArray(i).MimeType = MType
MimeMapObj.PutEx ADS_PROPERTY_UPDATE, "MimeMap", MimeMapArray
MimeMapObj.SetInfo
End Sub 说明: |
|---|
运行此脚本多次会在 Microsoft Internet 信息服务 (IIS) 5.0 或 Microsoft Internet 信息服务 (IIS) 6.0 元数据库中创建多个 MIME 映射项。 |
运行此脚本后,您可能不会从 Microsoft Internet 信息服务 (IIS) 5.0 或 Microsoft Internet 信息服务 (IIS) 6.0 Microsoft 管理控制台 (MMC) 中看到其他 MIME 类型。但是,这些 MIME 类型已添加到 Microsoft Internet 信息服务 (IIS) 5.0 或 Microsoft Internet 信息服务 (IIS) 6.0 元数据库中。下面的脚本将显示 Microsoft Internet 信息服务 (IIS) 5.0 或 Microsoft Internet 信息服务 (IIS) 6.0 元数据库中的所有 MIME 类型。
' This script lists the MIME types for an IIS Server.
' To use this script, just double-click or execute it from a command line
' by calling cscript.exe
dim mimeMapEntry, allMimeMaps
' Get the mimemap object.
Set mimeMapEntry = GetObject("IIS://localhost/MimeMap")
allMimeMaps = mimeMapEntry.GetEx("MimeMap")
' Display the mappings in the table.
For Each mimeMap In allMimeMaps
WScript.Echo(mimeMap.MimeType & " (" & mimeMap.Extension + ")")
Next将脚本另存为 .vbs 文件(例如,DiscoverIISMimeTypes.vbs),然后从命令提示窗口使用以下命令运行它:
cscript DiscoverIISMimeTypes.vbs