如何:設定 IIS 5.0 和 IIS 6.0 以部署 WPF 應用程式How to: Configure IIS 5.0 and IIS 6.0 to Deploy WPF Applications

您可以從大多數網頁伺服器部署 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 應用程式,只要這些伺服器是以適當的 多用途網際網路郵件延伸標準 (MIME)Multipurpose Internet Mail Extensions (MIME) 類型所設定。You can deploy a Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) application from most Web servers, as long as they are configured with the appropriate 多用途網際網路郵件延伸標準 (MIME)Multipurpose Internet Mail Extensions (MIME) types. 根據預設,Microsoft Internet Information Services (IIS) 7.0Microsoft Internet Information Services (IIS) 7.0 是以這些 MIMEMIME 類型所設定,但 Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 6.0Microsoft Internet Information Services (IIS) 6.0 則不是。By default, Microsoft Internet Information Services (IIS) 7.0Microsoft Internet Information Services (IIS) 7.0 is configured with these MIMEMIME types, but Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 5.0 and Microsoft Internet Information Services (IIS) 6.0Microsoft Internet Information Services (IIS) 6.0 are not.

本主題說明何設定 Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 6.0Microsoft Internet Information Services (IIS) 6.0,以部署 WPFWPF 應用程式。This topic describes how to configure Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 5.0 and Microsoft Internet Information Services (IIS) 6.0Microsoft Internet Information Services (IIS) 6.0 to deploy WPFWPF applications.

注意

您可以檢查UserAgent登錄,以判斷系統是否已安裝.NET Framework 中的字串。You can check the UserAgent string in the registry to determine whether a system has .NET Framework installed. 詳細資料和指令碼,以檢查UserAgent字串,以判斷系統上是否已安裝.NET Framework,請參閱偵測是否安裝.NET Framework 3.0 是For details and a script that examines the UserAgent string to determine whether .NET Framework is installed on a system, see Detect Whether the .NET Framework 3.0 Is Installed.

調整內容到期設定Adjust the Content Expiration Setting

您應該將內容到期設定調整為 1 分鐘。You should adjust the content expiration setting to 1 minute. 下列程序概述如何使用 IISIIS 執行此作業。The following procedure outlines how to do this with IISIIS.

  1. 按一下 [開始] 功能表,指向 [系統管理工具],然後按一下 [Internet Information Services (IIS) 管理員]。Click the Start menu, point to Administrative Tools, and click Internet Information Services (IIS) Manager. 您也可以從命令列使用 "%SystemRoot%\system32\inetsrv\iis.msc" 來啟動此應用程式。You can also launch this application from the command line with "%SystemRoot%\system32\inetsrv\iis.msc".

  2. 展開 IISIIS 樹狀目錄,直到找到 [預設的網站] 節點。Expand the IISIIS tree until you find the Default Web site node.

  3. 以滑鼠右鍵按一下 [預設的網站],然後從操作功能表選取 [屬性]。Right-click Default Web site and select Properties from the context menu.

  4. 選取 [HTTP 標頭] 索引標籤,然後按一下 [啟用內容到期日]。Select the HTTP Headers tab and click "Enable Content Expiration".

  5. 設定內容於 1 分鐘後過期。Set the content to expire after 1 minute.

註冊 MIME 類型和副檔名Register MIME Types and File Extensions

您必須註冊數種 MIMEMIME 類型和副檔名,用戶端系統上的瀏覽器才能載入正確的處理常式。You must register several MIMEMIME types and file extensions so that the browser on the client's system can load the correct handler. 您需要新增下列類型:You need to add the following types:

副檔名Extension MIME 類型MIME Type
.manifest.manifest application/manifestapplication/manifest
.xaml.xaml application/xaml+xmlapplication/xaml+xml
.application.application application/x-ms-applicationapplication/x-ms-application
.xbap.xbap application/x-ms-xbapapplication/x-ms-xbap
.deploy.deploy application/octet-streamapplication/octet-stream
.xps.xps application/vnd.ms-xpsdocumentapplication/vnd.ms-xpsdocument

注意

您不需要在用戶端系統上註冊 MIMEMIME 類型或副檔名。You do not need to register MIMEMIME types or file extensions on client systems. 當您安裝 Microsoft.NET Framework 時,它們會自動註冊。They are registered automatically when you install Microsoft .NET Framework.

下列 Microsoft Visual Basic Scripting Edition (VBScript) 範例會自動新增必要MIMEMIME類型 IISIISThe following Microsoft Visual Basic Scripting Edition (VBScript) sample automatically adds the necessary MIMEMIME types to IISIIS. 若要使用指令碼,請將程式碼複製到伺服器上的 .vbs 檔案。To use the script, copy the code to a .vbs file on your server. 然後,從命令列執行該檔案,或在 Microsoft Windows ExplorerMicrosoft Windows Explorer 中按兩下該檔案,以執行指令碼。Then, run the script by running the file from the command line or double-clicking the file in Microsoft Windows ExplorerMicrosoft 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.0Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 6.0Microsoft Internet Information Services (IIS) 6.0 Metabase 中建立多個 MIMEMIME 對應項目。Running this script multiple times creates multiple MIMEMIME map entries in the Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 5.0 or Microsoft Internet Information Services (IIS) 6.0Microsoft Internet Information Services (IIS) 6.0 metabase.

執行此指令碼之後,您可能不會從 Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 6.0Microsoft Internet Information Services (IIS) 6.0 Microsoft Management Console (MMC)Microsoft Management Console (MMC) 看到其他 MIMEMIME 類型。After you have run this script, you may not see additional MIMEMIME types from the Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 5.0 or Microsoft Internet Information Services (IIS) 6.0Microsoft Internet Information Services (IIS) 6.0 Microsoft Management Console (MMC)Microsoft Management Console (MMC). 不過,這些 MIMEMIME 類型已新增至 Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 6.0Microsoft Internet Information Services (IIS) 6.0 Metabase。However, these MIMEMIME types have been added to the Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 5.0 or Microsoft Internet Information Services (IIS) 6.0Microsoft Internet Information Services (IIS) 6.0 metabase. 下列指令碼會顯示 Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 6.0Microsoft Internet Information Services (IIS) 6.0 Metabase 中的所有 MIMEMIME 類型。The following script will display all the MIMEMIME types in the Microsoft Internet Information Services (IIS) 5.0Microsoft Internet Information Services (IIS) 5.0 or Microsoft Internet Information Services (IIS) 6.0Microsoft Internet Information Services (IIS) 6.0 metabase.

' 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),然後從命令提示字元使用下列命令來執行:Save the script as a .vbs file (for example, DiscoverIISMimeTypes.vbs) and run it from the command prompt using the following command:

cscript DiscoverIISMimeTypes.vbs