ASP.Net Content Delivery Network

date_range
20 January 2013

ASP.Net

Tutorial

I’ve updated this article here.

Whilst working on a project recently I came across a little problem whereby I needed to share LESS and jQuery scripts between MVC applications in the same solution. We all love the url helper methods that are included in MVC to get the path’s of content files using @Url.Content() method that will map a server path to a relative address.

Add Fakes Assembly
Solution Layout

Now that I was intending to use a CDN to host the stylesheets and scripts for the applications, that wasn’t going to fly as the files we no longer part of the same application domain path. It also sprung to mind that when locally debugging the application, making small adjustments to the files, I didn’t want to have to push the files up to the CDN everytime, so I decided to make the CDN it’s own project in the solution. The layout of the solution is now as shown in the image. Each of the main projects have a post-build event to start the content project when they are run.

I also made my own Url helper extension so that I didn’t have to manually set the base path of the CDN when publishing. It looks like this:

Using a compiler notation I check which configuration the DLL has been built with and then return the absolute path of the resource. It’s not perfect; I’d like it to set the port dynamically for local debugging using a value in the web.config.

I’d love to hear anyone elses take on the problem and any improvements I could make. I’ve got an interesting post to make over the coming days about persistence ignorant use of Entity Framework that I’m hoping should be quite useful.