EPiServer Azure Virtual Path Provider, part one

This blog post is about creating a virtual path provider for EPiServer CMS that can be used together with the Windows Azure platform. It’s the fourth installment in the “Running EPiServer on the Windows Azure Platform” series.

The challenge

cubeWriting to the file system where we house our website on Windows Azure is a big no-no. Instead we need to rely on either SQL Azure, Cloud Storage or Cloud Drives. With that said we have three possible solutions.

The first option to use a database virtual path provider is not a bad one – in fact it’s quite clever. Creating a new virtual path provider together with the cloud storage API is going to require a’lot of development effort. The third – and this is the option I went with – involves using a cloud drive which brings us as close to native EPiServer CMS functionality as possible.

How’s that? Cloud drives are virtual hard drives (VHD). We mount them in runtime and they behave like your normal NTFS-formatted drive. Awesome!

Wait. There’s a catch. Since we’re mounting it in runtime we cannot define the drive letter – it’s selected for us by Windows Azure. This is bad because since we do not have write-permissions to our website folder we cannot edit EPiServer.config to specify which drive-letter our VPPs are housed at. Argh – headache.

I’ll get back to this later. Let’s first have a look on how we use the cloud drives in a Windows Azure project.

Creating a virtual drive and uploading it to Windows Azure

The first task we’re going to be performing is creating the virtual drive that we’ll use as VPP storage and subsequently upload it to Windows Azure. First download Cloud Storage Studio for accessing cloud storage. It’s free to try.

Let’s get started by creating a virtual drive. I’m using Windows 7 and I hope you are too!

0. Disk management tool

Fire up the disk management tool. Wait for it to load. Takes a few seconds!

Now Action –> Create VHD. Name it EPiServerVPP.vhd and specify a location. Use fixed size with 16MB (feel free to make it larger). Azure does not support dynamically expanding drives (I learned this the hard way). Right click the new disk and initialize it with standard values. Next right click it again and select New Simple Volume. Again, all with default values.

InitializeDisk1. MountVHD

Next detach it but don’t delete it!

Fire up Cloud Storage Studio and connect using your Azure storage credentials. Expand the tree to containers and create a new container. Name it vhd.

Click upload Page Blob and select the VHD we just created. This stores our VHD as a blog up on the Windows Azure platform in the container vhd.

UploadWithCloudStorageStudio

Configuring the cloud project

We need to add a few settings in order to be able to use our cloud drive. Head into Visual Studio and open up properties for our cloud project. Create the settings as shown in the image below.

CloudProjectSettings

Make sure that the DataConnectionString is using default HTTP endpoints. Finally create a local storage called Local Cache with the size of 512MB as shown in the image below. This local storage will be used to cache the cloud drive in order to provide faster access.

LocalCache

Using WebRole to configure and setup the virtual drives

Using the Windows Azure platform we can inherit from the RoleEntryPoint-class.This class gives us access to initialization, callbacks, etc of the WebRole. From here we can manage objects before our website is initialized. This is traditionally named WebRole.cs and is by default included in your project.

Add the following to OnStart()

Next we’ll define the ConfigureAndSetupVirtualDrives()-method.

Define the ConfigureAndSetupSingleVirtualDrive()-method.

That takes care of mounting the drives. Now we when the WebRole shuts down we need to gracefully unmount them. Just like we mounted them in OnStart() we’ll unmount them from OnStop().

That takes care of initializing and mounting the cloud drives. But as I said in the beginning the receive a dynamic drive letter. So we cannot define the drive letter in EPiServer.config. Let’s take care of that in part 2!

daniel
daniel
Developer
Recent Posts
Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.

Not readable? Change text. captcha txt

Start typing and press Enter to search