I am creating an installer for a silverlight application and would like to be able to register the .xap extension for IIS automatically. Is there a way to accomplish this without editing the registry? If not, what registry entries to I need to make? Thanks!
+2
A:
- Start->run inetmgr (launch IIS management console)
- Click on MIME Types
- Click Add.. .xap application/x-silverlight-app
- Press OK
or you could save this code to a text file and execute it on the server:
AddMimeType.vbs
Dim VPath
'This changes setting at machine level, you may change it to a different path
VPath = "IIS://localhost/MimeMap"
'Add/Update the type for DLR language extension
UpdateMime ".xap", "application/x-silverlight-app"
'Search for the given extension and update its type
'when not found, add it into the collection
Sub UpdateMime(Extension, NewType)
Dim LocalMimeMap, MimeMap, MMItem, aMimeMapNew()
Dim i
i = 0
Const ADS_PROPERTY_CLEAR = 1
Const ADS_PROPERTY_UPDATE = 2
Set LocalMimeMap = GetObject(VPath)
MimeMap = LocalMimeMap.GetEx("MimeMap")
Dim found
found = False
For Each MMItem In MimeMap
ReDim Preserve aMimeMapNew(i)
Set aMimeMapNew(i) = CreateObject("MimeMap")
aMimeMapNew(i).Extension = MMItem.Extension
If MMItem.Extension = Extension Then
found = True
MsgBox("Update type of extension " + MMItem.Extension + " from " + MMItem.MimeType + " to " + NewType)
aMimeMapNew(i).MimeType = NewType
Else
aMimeMapNew(i).MimeType = MMItem.MimeType
End If
i = i + 1
Next
If found Then
LocalMimeMap.PutEx ADS_PROPERTY_UPDATE, "MimeMap", aMimeMapNew
LocalMimeMap.SetInfo
Else
MsgBox("Add new extension " + Extension + " with type " + NewType)
AddMime Extension, NewType
End If
End Sub
Sub AddMime(ExtensionToAdd, MimeTypeToAdd)
Dim LocalMimeMap, MimeMap
Dim i
Const ADS_PROPERTY_UPDATE = 2
Set LocalMimeMap = GetObject(VPath)
MimeMap = LocalMimeMap.GetEx("MimeMap")
i = UBound(MimeMap)+1
Redim Preserve MimeMap(i)
Set MimeMap(i) = CreateObject("MimeMap")
MimeMap(i).Extension = ExtensionToAdd
MimeMap(i).MimeType = MimeTypeToAdd
LocalMimeMap.PutEx ADS_PROPERTY_UPDATE,"MimeMap",MimeMap
LocalMimeMap.SetInfo
End Sub
Michael S. Scherotter
2009-02-11 18:23:08