Serving Asp.Net MVC4 pages on Mono with xsp. That is, with xsp4

I couldn't see why the command-line xsp command didn't work until I realised there is an not-very-well-advertised xsp4. At which point I guess the 2 in xsp2 means .Net 2 rather than, say, xsp version 2. So now I know that:

To run an Asp.Net 4 or 4.5 web application you need xsp4; whereas to run an Asp.Net 2 (or 3 or 3.5) app you need xsp2.

man xsp4 returns nothing, but the switches all seem to be the same as you'll find with man xsp. So to run your MVC4 web app from the command line, cd to the web app directory and just run xsp4.

Asp.Net MVC 4 on Mono and Windows

Having at last got an Asp.Net Mvc 4 project template working on the Mac/Xamarin/Mono, I came to grief again when deploying it to a Windows hosted server. The problem is that whereas mono works without Microsoft.Web.Infrastructure.dll (and indeed is likely to give errors if you have it), for hosting on Windows you must re-include it.
So my deploy process now includes putting Microsoft.Web.Infrastructure.dll back in the web application bin/ directory; and now I can develop on the Mac and deploy to a Windows Server.

Asp.Net MVC4 on Mono & Xamarin/MonoDevelop on Mac – The C# Template Project

Update Jan 2014: Go straight to github for MVC Templates for .Net 4 and .Net 4.5 or see asp-net-mvc4-net-framework-version-4-5-c-razor-template-for-mono-on-mac-and-linux for more recent notes.

I've been trying for a while to get this working. It all seemed so-near-and-yet-so-far. But here is the Visual Studio 2010 C# Asp.Net MVC4 Template Project which works on my Mac and (thanks to comment from Stephen) on Linux :
Visual Studio 2010 Asp.Net Mvc4 CS# Web Application Template modified for Mono

There's a list of issues which frustrated earlier attempts but the above link is to a project that does build and run on my Mac. Things to make it work included:

  • Got the latest Xamarin Studio, previously known as MonoDevelop
  • Mono version: I got MVC4 on Framework version 4 running on Mono 2.10.12; and MVC4 on Framework 4.5 on Mono 3.2.5. Nb I'm not sure whether everything related to async is currently working, but many web apps wouldn't want to use async.
  • There's a list of potential issues to address described in this stackoverflow post, I think what I did was just:
    • Delete Microsoft.Web.Infrastructure.dll from the bin directory
  • I also removed Entity Framework References. As of Jan 2014 that's not yet done on the Mono, although this may change shortly.
  • At first I commented out the line AreaRegistration.RegisterAllAreas(); in global.asax.cs Application_Start because it caused an error which appeared to refer to Entity Framework but that might just have been because I had removed System.Web.DynamicData too, so I put DynamicData back in.
  • The StyleBundles failed with a typo, or rather a case-sensitivity issue. A lot of .Net code is written on the assumption of a case-insensitive file system, but mono on *nix will usually have a case-sensitive filesystem, so you have to start being pedantic about getting the case correct. For instance App_Start/BundleConfig.cs referred to the file Site.css as site.css, so it wasn't found until I corrected it.
  • Having taking the 'intranet' template which uses Windows authentication, I changed the web.config line <deny users="?"></deny> to <allow users="?"></allow>. But this gives you no security. The simplest route back to a secure website is to instead put in forms authentication, I don't yet have a solution for windows authentication on mono.
  • I included all the nugetted package dlls in the zipfile, except that I deleted the EntityFramework stuff.

Kudos to all who worked so hard to make MVC4 on Mono possible. And of course to those who made MVC4 possible at all.