MIME-types and VPP
Yesterday i ran into a problem when i was moving an old JAVA-application from an Apache-server into i VPP-folder on our EPiServer site.
What i wanted to do was to host the JNLP-file and the JAR-files in a VPP-folder, and simple create a hyperlink to the JNLP-file from a web page, rather then have a separate Apache that only serves JNLP-files.
I knew it would be a bit of an issue to set the correct MIME-types for my JNLP-file when stored on a VPP-folder, so what i wanted was a flexible solution that would allow me to add other MIME-types if needed. Here is what i came up with:
First of all i added a handler in global.asax that is triggered when i file transmission starts.
1: void Application_Start(object sender, EventArgs e)
3: UnifiedFile.UnifiedFileTransmitting +=
Also in global.asax:
1: void UnifiedFile_UnifiedFileTransmitting(UnifiedFile sender,
3: if (sender == null || sender.Name == null || sender.Extension == null)
As you can see i don’t add a lot of code in global.asax, i prefer to create manager-classes. The UnifiedFileManager-class looks like this:
1: public static class UnifiedFileManager
3: public static void HandleMimeType(string Extension)
5: string HandledMimeTypes =
7: foreach (string HandledMimeType in HandledMimeTypes.Split("|".ToCharArray()))
9: string ThisMimeType = HandledMimeType.Split(";".ToCharArray());
10: if (ThisMimeType.Equals(Extension))
11: HttpContext.Current.Response.ContentType = ThisMimeType;
And the final step is to add a line in appSettings. This is where you store the MIME-types and their extensions:
<add key="HandledMimeTypes" value=".jnlp;application/x-java-jnlp-file" />
To add more MIME-types, simple separate them with a |-character, like this:
Now, i was able to launch my JNLP-file without any problems.