Skip to main content

Hosting .NET MVC on RackspaceCloud Cloud Sites

Last week I deployed a pet project (pun intended) of mine Borrow a Pet to the RackspaceCloud Cloud Sites environment.

So far I’m very pleased with the performance of the site, however I thought I would highlight a few areas you need to be aware of when developing/deploying .NET MVC apps to the Cloud Sites environment as their documentation right now is fairly light.
 
It should be said that the 24/7 Support team are fantastic, however I found myself having to use them a bit too often for my liking.

The technologies/tools/components I used goes like this.

  • .NET MVC for the Presentation Layer
  • LINQ to Entities for the data layer
  • SQL Server 2008 Database
  • Third Party Google Maps Wrapper for GeoCoding
  • Unity for the IoC Container

 

Medium Trust
Believe it or not but in my eight or so years of .NET development I’ve never had to develop with Medium Trust in mind. Boy had I been spoilt. For more details on Medium Trust information go to the knowledge base.

IIS7 Integration Mode
By default sites created on IIS7 are set to Classic Mode which means that if your using the .NET MVC Framework your routing won’t work. All you need to do is use the Live Chat support and ask them to change it to Integration Mode, they do it pretty much instantly.

AspJpeg
One of the requirements is to generate Thumbnails whenever an Image is uploaded, seems simple enough. RackspaceCloud advertise this component as being available. What they don’t do however is document that it DOES NOT work in the .NET environment and only works with Classic ASP.

http://www.aspjpeg.com/

I actually changed my Thumbnail Generation process to use this component on the understanding that it would work. You can imagine my reaction when I was told that this doesn’t work and that quote “if you recode in Classic ASP it will work”.

So rather than rewrite my clean, sexy Unit Testable MVC application I decided to just roll my own and go with the System.Drawing and System.Graphics libraries and it all works fine.

IoC
As I strictly practice TDD there was the need for an IoC Container to resolve any dependencies at runtime. I have religiously used Castle Windsor now for a couple of years. What I discovered however is that the Release Build of Castle Windsor does not work in a Medium Trust environment, there is a way to Rebuild the project however having tried to download the Castle source and build it before proved problematic. So I made the switch to Unity and all is well. So when choosing an IoC container make sure you use one which doesn’t use reflection internally.

Impersonation
This one is fairly simple, but you will need to impersonate your NT account (same as the FTP account ) if you plan on doing any System.IO operations. This can be set by adding the Identity element to your Web.Config

<system.web> <identity impersonate="true" userName="dfw\username" password="strongpassword"></identity> </system.web/>

Email
There are some Rules around using the Cloud Site’s mail relays.
You can only send 25 emails at a time and no more than 250 messages in a 20 minute period. If you want to send more than this then you need to contact Rackspace.

As I use Google Apps for all my email, my MX records were pointing to Google’s servers. This isn’t a problem so long as you set up an email account via the Rackspace UI then use those credentials when specifying the Network Credentials in the Smtp object like below.

var smtpClient = new SmtpClient(host, port) { Credentials = new NetworkCredential(fromEmail, smtpPassword), DeliveryMethod = SmtpDeliveryMethod.Network, }; smtpClient.Send(mailMessage);

Your Smtp Host to use is mail.yourdomainname.com and port 25 is fine.

The knowledge base lists all the mail servers available.

Third Party Libraries
One of the key features of the site is Location based personalization which provides content to users based on their geographical location. In order to achieve this I needed to GeoCode the User addresses at account creation time.

For this I used Geocoding-net which is an awesome C# wrapper for Google Maps, Virtual Earth and Yahoo Maps.

By default though it didn’t work in a partially trusted environment. Fortunately I was able to get the source and add the following attribute to AssemblyInfo.cs and this was enough to get it work.

[assembly: AllowPartiallyTrustedCallers]

When analysing third party components make sure they support Partially trusted and if not make sure you have access to the source code.

If you take note of these limitations/restriction and are still able to provide all the functionality of your application then the gains can be massive.

Overall the Cloud Sites model is very attractive and is more inline with Windows Azure. What Cloud Sites allows you to do is focus on features and not get bogged down with Server Administration, which I for one am no fan of.

Popular posts from this blog

Freeing Disk Space on C:\ Windows Server 2008

  I just spent the last little while trying to clear space on our servers in order to install .NET 4.5 . Decided to post so my future self can find the information when I next have to do this. I performed all the usual tasks: Deleting any files/folders from C:\windows\temp and C:\Users\%UserName%\AppData\Local\Temp Delete all EventViewer logs Save to another Disk if you want to keep them Remove any unused programs, e.g. Firefox Remove anything in C:\inetpub\logs Remove any file/folders C:\Windows\System32\LogFiles Remove any file/folders from C:\Users\%UserName%\Downloads Remove any file/folders able to be removed from C:\Users\%UserName%\Desktop Remove any file/folders able to be removed from C:\Users\%UserName%\My Documents Stop Windows Update service and remove all files/folders from C:\Windows\SoftwareDistribution Deleting an Event Logs Run COMPCLN.exe Move the Virtual Memory file to another disk However this wasn’t enough & I found the most space was

3 Reasons Why Progressive Web Apps (PWAs) Won’t Replace Native Apps

Many people believe Progressive Web Apps (PWAs) are the future of the mobile web, but in my opinion, PWAs are not a replacement for native mobile apps. Here are three reasons why: 1. Native mobile apps provide a smoother & faster experience  Mobile websites, progressive or otherwise are slower and not as smooth. 90% of the time spent is spent using apps vs the browser . The single most significant contributing factor to a smooth experience on mobile is the speed of the network and latency of the data downloaded and uploaded. When you visit websites on desktop or mobile, there is a lot of third-party code/data that gets downloaded to your device, which more often than not has zero impact on the user experience. This includes: CSS (Cascading Style Sheets) JavaScript Ad network code Facebook tracking code Google tracking code The median number of requests a mobile website makes is a shocking  69 . On the other hand, native apps only get the data that is requi

Unit Testing Workflow Activities in .NET 4.0

  Recently during a catch up with my buddy Keith Patton I was (as I tend to do) singing the praises of the Workflow in .NET 4.0. The all important question about Unit Testing support was raised, I tried as best as I could to explain the new In and Out Arguments but I didn’t feel I was convincing enough, so I though I would clarify with a blog post. If you developed Workflows in .NET 3.5 then you will be well aware of the lack of Unit Test support which was due to many reasons but mostly in part to the complex Workflow hosting environment. When moving to .NET 4.0 Workflow Foundation from .NET 3.5 it pays to be conscious of that fact that there is no longer a distinction between Activities and Workflows. Everything derives from the System.Activities.Activity class. So the definition of a Workflow is just a collection of of 1 or more Activities. I have designed a very simple Rental Car Activity which takes the an Applicants age as the input and outputs a True or False depending o