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.

Comments

  1. "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."

    Man, you can say THAT again.

    I am on with the support team at LEAST twice a day, every day.

    ...and it's not because I'm a whiner. These are "site down" reports, and I have them just about daily with RackSpaceCloud.

    In my opinion, they are trying to grow FAR too quickly with their latest marketing blitz, and it is affecting the reliability of their entire network. Think about how many people are signing up with them each month (including you! lol).

    I also run a primarily Microsoft web site (with all sorts of technologies as part of that umbrella VS.NET, IIS, SQL Server, etc) and I've had literally 15 outages in the past 45 days. The site has been down for more than a WEEK at a time! To be fair, most of these were related to the same issue, which was described at the time as "we can't figure out what's going on".

    Nice.

    Anyway, as developers, we have our own work to do, and it doesn't need to be compounded by a host with questionable reliability.

    The site has been down due to connectivity issues, security issues, failing hardware, scheduled and unscheduled maintenance blackouts and "misbehaving nodes".

    Anyway, I am getting away from RackSpaceCloud as quickly as possible and moving to a dedicated server.

    Maybe now I can concentrate on my own code instead of doing tech support for RSC.

    ReplyDelete
  2. Thanks Will. I ran into the same problem with the Geocoding-net and our Cloud Site with RackSpace. How were you able to get the source code and change the assembly? I can only seem to find the actual compiled DLL.

    ReplyDelete
  3. The Source is hosted on Google Code http://code.google.com/p/geocoding-net/ and you can get a read-only copy from the SVN repository at http://geocoding-net.googlecode.com/svn/trunk/

    I can send you the compiled DLL I use which is Medium-Trust ready if you'd like.

    ReplyDelete

Post a Comment

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\TempDelete all EventViewer logs Save to another Disk if you want to keep themRemove any unused programs, e.g. FirefoxRemove anything in C:\inetpub\logsRemove any file/folders C:\Windows\System32\LogFilesRemove any file/folders from C:\Users\%UserName%\DownloadsRemove any file/folders able to be removed from C:\Users\%UserName%\DesktopRemove any file/folders able to be removed from C:\Users\%UserName%\My DocumentsStop Windows Update service and remove all files/folders from C:\Windows\SoftwareDistributionDeleting 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 cleared by using the Disk Cleanup to…

CPF Contribution Rates for new Singapore Permanent Residents (SPR’s)

Recently my wife and I applied and got approved for Singapore Permanent Residency. After completing the formalities the most significant immediate change is the contribution to CPF which is Singapore’s mandatory social security savings scheme requiring contributions from employers and employees. CPF contributions start from the date you obtain SPR status, which is the date of the entry permit.   Being a relentless budgeter I needed to know exactly how much I and my employer would have to contribute so that I could adjust my budget accordingly as the employee contributions get deducted from the monthly salary. After doing some research I discovered that there is a “graduated” approach to CPF contributions for new SPR’s where the contributions gradually increase in the first and second year and then upon reaching the third year are at the full amount. Note: There is an option for employers to contribute the full amount for year 1 and year 2 and the employee can use the graduated rate, b…

Implementing Custom Castle Windsor Facilities

If you’ve been following my posts you would know that I love Castle Windsor. One of the many useful features I have found is the Facility and I’m going to try and give a good example how you can make use of this. In a recent post I showed how you can add Cross-Cutting concerns to your application by using Interceptors.Now when configuring the Container you can explicitly configure each Interceptor per Service but when you have lot’s of components it can get pretty hard to maintain after a while and can also introduce subtle issues if someone forgets to configure it correctly.Below is how you would configure your Container without using a Facility. On the last line we are specifying the Interceptor explicitly. public void Configure() { container = new WindsorContainer(); container.Register( Component.For<CacheInterceptor>(), Component.For<ICacheProvider>() .ImplementedBy<WebCache…