HOW TO:設定 IIS 5.0 和 IIS 6.0 以部署 WPF 應用程式
更新:2007 年 11 月
您可以從大部分的 Web 伺服器部署 Windows Presentation Foundation (WPF) 應用程式,只要伺服器是以適當的多用途網際網路郵件延伸標準 (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。如需詳細資訊和檢查用於判斷系統是否有安裝 .NET Framework 的 UserAgent 字串的指令碼,請參閱 HOW TO:偵測有無安裝 .NET Framework 3.0。 |
調整內容到期日設定
您應該將內容到期日設定調整為 1 分鐘。下列程序概述如何使用 IIS 進行這個作業。
按一下 [開始] 功能表,指向 [系統管理工具],然後按一下 [網際網路資訊服務 (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 Metabase 中建立多個 MIME 對應項目。 |
執行這個指令碼後,可能不會從 Microsoft Internet Information Services (IIS) 5.0 或 Microsoft Internet Information Services (IIS) 6.0Microsoft Management Console (MMC) 看到其他的 MIME 類型。然而,這些 MIME 類型已經加入到 Microsoft Internet Information Services (IIS) 5.0 或 Microsoft Internet Information Services (IIS) 6.0 Metabase。下列指令碼會顯示 Microsoft Internet Information Services (IIS) 5.0 或 Microsoft Internet Information Services (IIS) 6.0 Metabase 中的所有 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