How to get ASP.NET MVC3 Working under Mono 2.10 (Ubuntu 12.10)

I've managed to get Mono (version 2.10.8.1) working with MVC3 in my Apache server through mod-mono and mono-server4.

Update: Included a DirectoryMatch configuration for securing various ASP.net directories.

Visual Studio Project Settings

Required References (Copy Local: True):

  • System.Web.Mvc
  • System.Web.Helpers
  • System.Web.Routing
  • System.Web.Razor
  • System.Web.WebPages
  • System.Web.WebPages.Razor
  • System.Web.WebPages.Deployment

References you must not deploy (Copy Local: False):

  • Microsoft.Web.Infrastructure
  • System.Web

Tip: If you are deploying additional references that aren't listed here and are receiving server errors, try turning off deployment of the additional references until you succeed.

Sample Web.config:

Note:  This configuration also includes a working example of dotless.

<configuration>
  <configSections>
    <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <customErrors mode="On" defaultRedirect="~/Error" />
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
    <authentication mode="None"></authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
    <httpHandlers>
      <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
    </httpHandlers>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <add name="dotless" path="*.less" verb="*" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Abstractions" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <dotless minifyCss="false" cache="true" web="false" />
</configuration>

Ubuntu 12.10 Packages

The following should install everything required in Ubuntu 12.10:

sudo apt-get install libapache2-mod-mono mono-apache-server4 mono-devel mono-runtime

Apache2 Mod-Mono Configuration:

AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascx
DirectoryIndex index.aspx

<IfModule mod_mono.c>
  MonoUnixSocket default /tmp/.mod_mono_server4
  MonoServerPath default /usr/bin/mod-mono-server4
  AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascx
  MonoApplicationsConfigDir default /etc/mono-server4
  MonoPath default /usr/lib/mono/4.0:/usr/lib:/usr
</IfModule>

Apache2 Virtual Host Configuration:

<VirtualHost *:80>
  ServerName mono.host.tld

  MonoServerPath monotest "/usr/bin/mod-mono-server4"
  MonoDebug monotest true
  MonoSetEnv monotest MONO_IOMAP=all
  MonoApplications monotest "/:/server/home/monotest/www"

  DocumentRoot "/server/home/monotest/www"

  <Directory "/server/home/monotest/www">
    Options Indexes Includes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    Deny from env=blocked
 
    MonoSetServerAlias monotest
    SetHandler mono
  </Directory>

  <DirectoryMatch "/(bin|App_Code|App_Data|App_GlobalResources|App_LocalResources)/">
    Order deny,allow
    Deny from all
  </DirectoryMatch>

</VirtualHost>
Mastodon: @[email protected]