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

ASP.NET MVC Release Candidate - Upgrade issues - Spec#

First of all, great news that the ASP.NET MVC Release Candidate has finally been released.  Full credit to the team for the hard work on this.  You can get the download here  However this is the first time I have had upgrade issues.  Phil Haack has noted some of the issues here   If like me you have lot's of CTP's and Add-Ins then you might experience some pain in Uninstalling MVC Beta on Vista SP1  This is the list of Add-Ins / CTP's I had to uninstall to get it to work  Spec# PEX Resharper 4.1  Sourcelinks ANTS Profiler 4   Can't say I'm too impressed as it wasted over an hour of my time.  As it turned out Spec# turned out to be the offending culprit, it's forgiveable to have issues with a third party product but a Microsoft one? Guess no-one on the ASP.NET team has Spec# installed. 

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

Consuming the SSRS ReportExecutionService from a .NET Client

  I’ve just finished writing a nice wrapper which internally calls the SSRS ReportExecutionService to generate reports. Whilst it was fairly simple to implement there has been some major changes between 2005 and 2008 and the majority of online and documentation is based on the 2005 implementation. The most important change is that the Report Server and Report Manager are no longer hosted in IIS which will be a welcomed change to Sys Admins but makes the security model and hosting model vastly different. So far I’ve yet to figure out how to allow Anonymous Access, if anyone knows how to do this leave a comment and it will be most appreciated. Getting Started To get started you’ll want to add a service reference to http://localhost/ReportServer_SQL2008/ReportExecution2005.asmx where ReportServer_SQL2008 is the name you configure in the Reporting Services Configuration Manager. The Web Application files are located in C:\Program Files\Microsoft SQL Server\MSRS10.SQL2008\R