Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 Configure IIS 5.0 and IIS 6.0 to De...
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Windows Presentation Foundation
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, but Microsoft Internet Information Services (IIS) 5.0 and 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.

NoteNote:

You can check the UserAgent string in the registry to determine whether a system has .NET Framework installed. For details and a script that examines the UserAgent string to determine whether .NET Framework is installed on a system, see How to: Detect Whether the .NET Framework 3.0 Is Installed.

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.

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.

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 MIME map entries in the Microsoft Internet Information Services (IIS) 5.0 or Microsoft Internet Information Services (IIS) 6.0 metabase.

After you have run this script, you may not see additional MIME types from the Microsoft Internet Information Services (IIS) 5.0 or Microsoft Internet Information Services (IIS) 6.0 Microsoft Management Console (MMC). However, these MIME types have been added to the Microsoft Internet Information Services (IIS) 5.0 or Microsoft Internet Information Services (IIS) 6.0 metabase. The following script will display all the MIME types in the Microsoft Internet Information Services (IIS) 5.0 or Microsoft 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

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

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Configuring File MIME Types for Silverlight on IIS      Configuring File MIME Types for Silverlight on IIS ... alexrait1   |   Edit   |   Show History

Global.asax file code executed during application startup to make sure server support silverlight mimetype with extension ".xap"


<%@ Application Language="C#" %>
<%@ Import Namespace="System.DirectoryServices"%>

<script runat="server">
void Application_Start(object sender, EventArgs e)
{

string extension = ".xap";
string mimeType = "application/x-silverlight-app";

using (DirectoryEntry mimeMap = new DirectoryEntry("IIS://Localhost/MimeMap"))
{
PropertyValueCollection mimeTypes = mimeMap.Properties["MimeMap"];

bool mimeMapExists = false;
foreach (IISOle.IISMimeType iisMimeType in mimeTypes)
{
if (iisMimeType.Extension == extension)
mimeMapExists = true;
}
if (!mimeMapExists)
{
IISOle.MimeMapClass newMimeType = new IISOle.MimeMapClass();
newMimeType.Extension = extension; // string - .xap
newMimeType.MimeType = mimeType; // string - application/x-silverlight-app
mimeTypes.Add(newMimeType);
mimeMap.CommitChanges();
}
}

}

void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}

void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}

</script>

type missing      cyberchoya ... Thomas Lee   |   Edit   |   Show History
the list of types needed miss the following one that is very important.

.xap application/x-silverlight-app

it may not apply for this case because is WPF related but since I got into this page looking for the types needed for silverlight I guess somebody else could need that.

Serving .config and .exe.config files from IIS      Chango V. - MSFT   |   Edit   |   Show History
By default, IIS is configured to block serving of .config files (among others) to prevent disclosure of security-sensitive information from the server. HTTP error codes of 401 (Unauthorized) or 404 are returned. For an application like an XBAP meant to be run on the client side, you need to change this setting to be able to use a .exe.config file. See http://msdn.microsoft.com/en-us/library/ms689460.aspx.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker