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.
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.
IoCAs 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.