Introduction
A few days ago I had a requirement to test and run a ASP.NET page on Linux on Mono .NET framework. Mono is an open source project led by Novell to create an Ecma standard compliant, .NET-compatible set of tools, including among others a C# compiler and a Common Language Runtime. Mono can be run on Linux, BSD, UNIX, Mac OS X, Solaris and Windows operating systems.
There are loads of documenation on MONO site and there are numerous configurations options available. In this post I've listed down the steps on how to quickly get your first ASP.NET page up and running on a Linux platform.
Steps
1) Install Mono Extension: If you are working on SUSE platform, you have to install Mono extension, you can download the evaluation or commercial package from here. SUSE platform comes with inbuilt MONO framework; however, this version of Mono is not built to be a platform to host ASP.NET and other .NET server applications. That's why you need to install the extension, which includes latest .NET features, such as ASP.NET 2.0 , AJAX, MVC and it can also be upgraded when new features of .NET becomes available in Mono.
The installation is very straight forword. Once you have downloaded the ISO file, run Yast to add this software. The full installation intructions is here.
2) Configure Apache to load Mono: Open the apache config file. The config file name is httpd.conf and it is usually in /etc/apache2 directory, add following line in httpd.conf
Include /opt/novell/mono/mod_mono.conf
The actual path to mod_mono.conf might vary depending on the distribution you use or the path where you installed apache.
Mod_Mono is an Apache module that provides ASP.NET support for the Apache web server. Click here if you interested in more details.
3) Configure the mod_mono.conf: The mod_mono configuration defaults to running the 1.0 runtime for applications, if you want to use the 2.0 runtime, you can just use the MonoServerPath directive to point to the 2.0 server, like this:
MonoServerPath "/usr/bin/mod-mono-server2"
4) Restart the Apache service: After changing the configuration files, you have to restart the apache service, use the following command:
apache2ctl restart
5) Copy or create the new ASP.NET website: You can copy or create simple ASP.NET page in the Apache2 www home directory. In my environment it is /srv/www/htdocs. You can find the settings in httpd.conf file. In this folder you can create a new folder names MonoTest. So if you just copy and paste a simple ASP.NET hello world page to /srv/www/htdocs/MonoTest/. Assuming the hello world page file name is HelloWorld.aspx, then after you have copied the files browse to http://localhost/MonoTest/HelloWorld.aspx and you should see your first ASP.NET page up and running in the Linux platform.
The interesting fact is Mono can run sites which are precompiled using Visual Studio and there is no need to recompile in Mono.
6) Update the web.config file: A point to note is that mono only supports None or Forms Authentication mode and in Visual Studio the authentication mode defaults to Windows. So you probably have to update the setting in the web.config in case you getting authentication error in step 5, see following:
<authentication mode="[None|Forms]">