HowTo Run ASP.NET on Linux With Apache Web Server (Mono + Mod_Mono)

Mono is an open source project led by Novell (formerly by Ximian) 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. With Apache mod_mono we can run ASP.NET with C# on Linux machine. Mono is not just an ASP.NET interpreter, it also build a windows form and run on Linux, BSD, UNIX, Mac OS X, Solaris and Windows operating systems. But for now i just want to show you how to run an ASP.NET application on Linux machine.

Ok, get let’s start. Follow these steps (for ubuntu):
1. You need to install several library for mono. Type this command:

# sudo apt-get install mono-xsp2 mono-apache-server2 libapache2-mod-mono mono-gmcs mono-utils

2. After it finish you need to edit your mod_mono.conf. The easiest way to run Asp.Net application is using
 AutoHosting configuration as example below:
AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascx
DirectoryIndex index.aspx
MonoAutoApplication enabled
MonoServerPath "/usr/bin/mod-mono-server2"

You can read more about AutoHosting here or manual hosting configuration here, for ubuntu user please refer to this documentation.
3. Save the file and restart your apache.
4. Now let’s start write the first Asp.Net application. You can copy the text below:
Filename: hello.aspx

<%@ Page language="c#" src="hello.aspx.cs"
Inherits="HelloApp.HelloPage" AutoEventWireup="true" %>
	<title>First Mono ASP.NET Application</title>
	<form  runat="server">
	  Enter your name: <asp:TextBox id="name" runat="server" />
	  <asp:Button id="greet" Text="Greet" onClick="OnGreetClick" runat="server"/>
	<br /><strong><asp:Label id="message" runat="server">Hello, World!

Filename: hello.aspx.cs

using System;
using System.Web.UI.WebControls;
namespace HelloApp
public class HelloPage : System.Web.UI.Page
protected Label message;
protected Button greet;
protected TextBox name;
public void OnGreetClick(Object sender, EventArgs e)
message.Text = "Hello, " + name.Text;

5. Ok now save file to your web server. Mine is at the /var/www/firstaspnet/

6. And you will see your first Asp.Net application run on Linux OS.

If you like this post, please leave me a comment. Have a nice day.

Article by Vijay Nayani

  1. #1 by Shweta on February 23, 2011 - 12:49 AM

    Hi Vijay

    Can u plz provide me same installation for REDHAT LINUX ENTERPRISE 5???

    I really need it.

    thanx & regards

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: