다음을 통해 공유


How to: Configure IIS 5.0 and IIS 6.0 to Deploy WPF Applications

You can deploy a Windows Presentation Foundation (WPF) application from most Web servers, as long as they are configured with the appropriate Multipurpose Internet Mail Extensions (MIME) types. By default, Microsoft Internet Information Services (IIS) 7.0 is configured with these MIME types. although Microsoft Internet Information Services (IIS) 5.0 or Microsoft Internet Information Services (IIS) 6.0 are not.

This topic describes how to configure Microsoft Internet Information Services (IIS) 5.0 and Microsoft Internet Information Services (IIS) 6.0 to deploy WPF applications.

This topic contains the following sections.

  • Adjust the Content Expiration Setting
  • Register MIME Types and File Extensions
NoteNote:

You can check the UserAgent string in the registry to determine whether a system has .NET Framework 3.0 installed. See How to: Detect Whether .NET 3.0 is Present for details and a script that examines the UserAgent string to determine whether .NET Framework 3.0 is installed on a system.

Adjust the Content Expiration Setting

You should adjust the content expiration setting to 1 minute. The following procedure outlines how to do this with IIS.

  1. Click the Start menu, point to Administrative Tools, and click Internet Information Services (IIS) Manager. You can also launch this application from the command line with "%SystemRoot%\system32\inetsrv\iis.msc".

  2. Expand the IIS tree until you find the Default Web site node.

  3. Right-click Default Web site and select Properties from the context menu.

  4. Select the HTTP Headers tab and click "Enable Content Expiration".

  5. Set the content to expire after 1 minute.

Register MIME Types and File Extensions

You must register several MIME 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 Type

.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

NoteNote:

You do not need to register MIME types or file extensions on client systems. They are registered automatically when you install Microsoft .NET Framework version 3.0.

The following Microsoft Visual Basic Scripting Edition (VBScript) sample automatically adds the necessary MIME types to IIS. To use the script, copy the code to a .vbs file on your server. Then, run the script by running the file from the command line or double-clicking the file in 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
NoteNote:

Running this script multiple times creates multiple entries in the IIS MimeMap.