Startups and .NET
Wednesday, 18 May 2011
Piehead recently blogged "Why startups could use .NET but don't". Since Showcase Lane is written in ASP.NET MVC I thought I'd share why I chose this route and and how it turned out in the end.
Firstly, here's the original article that prompted me to write this post - http://www.piehead.com/blog/2011/05/why-startups-could-use-net-but-don%E2%80%99t.
There's nothing in that post that I disagree with, except to say the cost is probably another contributing factor - both the cost of development tools and server costs - Windows based hosting tends to be more expensive than Linux hosting.
My most recent project Showcase Lane and several before it were all written and developed in ASP.NET MVC but they all run flawlessly under Mono. This lets me run it on a cheap $20/month Linode server but still get all the benefits of compiled code and awesome development tools.
In this post I thought I'd write up why I chose this approach, the final web stack that I deploy to and cover a few of the minor issues I encountered along the way.
So the obvious first question is why I chose ASP.NET MVC as a platform. It comes down to a few simple facts:
- I really like C# as a language. Being a long time C++ developer I like strongly typed compiled languages and I truly believe that C# is one of the most progressive and continually improving languages available - LINQ, lambdas, anonymous types, dynamic and static typing and more. It's clean, powerful, flexible, fast and has a huge library of third party components (check out Nuget for example).
- Familiarity - I've used ASP.NET MVC in a number of work related projects and already new it well.
- Tooling - Visual Studio is in my mind the best IDE available. Powerful editing, debugging, accurate Intellisense, fast symbol browsing, fast compilation - it's all there.
- Mono - the ability to run on Windows or Linux based servers means no lock in and the possibility of cheaper server hosting costs.
Although I use Visual Studio 2010, I believe you could just as easily use the free Visual Studio Express editions or MonoDevelop and have a completely free development environment and web stack.
The Web Stack
- OS - Windows 7 x64
- IDE - Visual Studio 2010
- Language - C#
- Framework - ASP.NET MVC 2 (haven't upgraded to 3 yet, but it did work in a test project)
- Runtime - Microsoft .NET
- Database - MySQL (running on the staging server described below)
- ORM - PetaPoco (of course)
- Web Server - IIS 7
- Deployment - IIS virtual directory pointed to project build directory.
- OS - OpenSUSE 11.4 x64 on Virtual Box
- Database - MySQL
- Runtime - Mono 2.8
- Web Server - Lighttpd -> Mono Fast CGI server.
- Deployment - Visual Studio Publish tool via Samba to shared folder
- OpenSUSE 11.4 x64 on Linode
- Same configuration as staging server.
- Deployment - RSync from staging server to production server via SSH
Deploying ASP.NET MVC to Mono was smoother than I expected, but not without issues. Here's the main things I encountered:
- Issues with Mono's Fast CGI - there are a number of critical bugs in Mono's FastCGI server - mostly comms problems between the web server and the fast CGI server. These are all resolved in Mono 2.10. Not wanting to go too bleeding edge I simply built the 2.10 fast cgi server under Mono 2.8 and haven't had any issues since.
- MySQL data provider - you can't deploy the Windows MySQL data provider DLL to Mono 2.8 - it gives errors relating to distributed transaction support. Grabbing the latest Mono connector from the MySQL site resolved this.
- Lighttpd's index.html - Lighttpd insists on passing "index.html" as the requested file for the root request on a domain which confuses MVC's default routing rules. I worked around this with a simple rewrite rule in the ASP.NET project (a few lines of code).
- Image Resizing - Mono's default implementation of GDI+ yields poor quality image resampling. I resolved this by interoping to ImageMagick. See here.
- Case Sensitivity Issues - Occasionally I've had issues with the case of view and master page filenames and with routing rules - easy to work around once you're aware of it.
All in all I'm really happy with the final web stack that I've settled on. It provides an excellent balance of powerful tools, a language and framework I like, the performance of a compiled code and the ability to deploy on cheap Linux servers.
One final note... I definitely planned for this web stack from the start, deliberately choosing MySQL over SQL Server and testing on both Windows/.NET and Linux/Mono each step of the way. To move to this platform after developing an entire product on Windows probably wouldn't go so smoothly.
I realize this web stack wont be to the taste of everyone, but if you're trying to decide on a platform I certainly think .NET/Mono is worth considering.
Leave a comment