Jonas Lindau
Apr 1, 2011
  3759
(0 votes)

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)
   2:  {
   3:      UnifiedFile.UnifiedFileTransmitting += 
               new UnifiedFileEventHandler(UnifiedFile_UnifiedFileTransmitting);
   4:  }

 

Also in global.asax:

   1:  void UnifiedFile_UnifiedFileTransmitting(UnifiedFile sender, 
           UnifiedVirtualPathEventArgs e)
   2:  {
   3:      if (sender == null || sender.Name == null || sender.Extension == null)
   4:          return;
   5:   
   6:      UnifiedFileManager.HandleMimeType(sender.Extension);
   7:  }

 

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
   2:  {
   3:      public static void HandleMimeType(string Extension)
   4:      {
   5:          string HandledMimeTypes = 
                   ConfigurationManager.AppSettings["HandledMimeTypes"].ToString();
   6:   
   7:          foreach (string HandledMimeType in HandledMimeTypes.Split("|".ToCharArray()))
   8:          {
   9:              string[] ThisMimeType = HandledMimeType.Split(";".ToCharArray());
  10:              if (ThisMimeType[0].Equals(Extension))
  11:                  HttpContext.Current.Response.ContentType = ThisMimeType[1];
  12:          }
  13:      }
  14:  }

 

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:

<add key="HandledMimeTypes" 
value=".jnlp;application/x-java-jnlp-file|.pdf|application/octet-stream" />

Now, i was able to launch my JNLP-file without any problems.

Apr 01, 2011

Comments

Please login to comment.
Latest blogs
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024