您可以从大多数 Web 服务器部署 Windows Presentation Foundation (WPF) 应用程序,前提是这些服务器配置了适当的Multipurpose Internet Mail Extensions (MIME) 类型。 默认情况下,Microsoft Internet Information Services (IIS) 7.0 配置有这些MIME 类型,但 Microsoft Internet Information Services (IIS) 5.0 和 Microsoft Internet Information Services (IIS) 6.0 则不然。
本主题介绍如何配置 Microsoft Internet Information Services (IIS) 5.0 和 Microsoft Internet Information Services (IIS) 6.0 来部署 WPF 应用程序。
本主题包括下列各节。
- 调整内容过期设置
- 注册 MIME 类型和文件扩展名
![]() |
---|
您可以检查注册表中的 UserAgent 字符串,确定系统是否安装了 .NET Framework。有关检查 UserAgent 字符串以确定系统是否安装了 .NET Framework 的详细信息和脚本,请参见如何:检测是否安装了 .NET Framework 3.0。 |
调整内容过期设置
您应当将内容过期设置调整为 1 分钟。 下面的过程简要介绍了如何对 IIS 执行此操作。
单击**“开始”菜单,指向“管理工具”,然后单击“Internet 信息服务(IIS)管理器”**。 您还可以使用“%SystemRoot%\system32\inetsrv\iis.msc”从命令行启动此应用程序。
展开 IIS 树,直到找到**“默认网站”**节点。
右击**“默认网站”,从上下文菜单中选择“属性”**。
选择**“HTTP 头”**选项卡,然后单击“启用内容过期”。
将内容设置为 1 分钟后过期。
注册 MIME 类型和文件扩展名
必须注册几种 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 Explorer中双击此文件来运行脚本。
' 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 Information Services (IIS) 5.0 或 Microsoft Internet Information Services (IIS) 6.0 元数据库中创建多个 MIME 映射项。 |
运行此脚本后,您可能不会从 Microsoft Internet Information Services (IIS) 5.0 或 Microsoft Internet Information Services (IIS) 6.0 Microsoft Management Console (MMC) 中看到其他 MIME 类型。 但是,这些 MIME 类型已添加到 Microsoft Internet Information Services (IIS) 5.0 或 Microsoft Internet Information Services (IIS) 6.0 元数据库中。 下面的脚本将显示 Microsoft Internet Information Services (IIS) 5.0 或 Microsoft Internet Information Services (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