Registrati Tipi Silverlight MIME in IIS a livello di programmazione
-
22-08-2019 - |
Domanda
Sto creando un programma di installazione per un'applicazione Silverlight e vorrei essere in grado di registrare l'estensione Xap per IIS automaticamente. C'è un modo per ottenere questo risultato senza modificare il Registro di sistema? Se no, che le voci del Registro di sistema ho bisogno di fare? Grazie!
Soluzione
- Start-> inetmgr eseguire (lancio IIS console di gestione)
- Fare clic su tipi MIME
- Fare clic su Aggiungi .. Xap application / x-silverlight-app
- Premere OK
o si potrebbe salvare questo codice in un file di testo ed eseguirlo sul 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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow