Configuring and running Mono ASP.NET 3.5 (AJAX.NET) on Linux computers

24 ביולי 2008

8 תגובות

[This blog was migrated. You will not be able to comment here.
The new URL of this post is]

Before we will start, we should install Linux. To do this, you can download any of LiveCDs with live installation. Officially, Mono supported only on one free Linux – openSuse. However, you can make it work on any RedHat (and its alternatives), OpenSolaris. It works, but unsupported on Debians, Ubuntu and Maemo. We’ll stick to openSuse by now.


Let’s install it – OS

I’m assuming, that you’re installing Linux as the only OS on the machine, so insert liveCD (it can be either Gnome or KDE) and wait for Linux to run. It will run live image directly on your machine without installation.

When it’ll up, you’ll see liveInstall icon in your desktop. Click it and skip first two screens (it is only language and local settings). Next screen (disk partitions) is necessary for us.

On this screen, first delete all automatic partitions. The only one main partition will remain (/DEV/SDA or /DEV/HDA). Next you should choose non-LVM option and then start creating partitions.

Create first partition with mount point /boot and size of 100Mb. File system for this partition should be ext3.

Create second partition with file system SWAP (you will not have mount point) and set the size twice bigger, then RAM amount.

Create last partition with mount point / and all remaining size on disk.

All other steps are optional, you can just click Next button.

After about 10 minutes you’ll have up and running openSuse system. (If you forgot to remove CD, choose HardDisk as boot option)

Web Server installation

Now we have to install web server. You can choose either Apache, FastCGI  or use build-in server within Mono – XSP. We’ll choose Apache

Goto “Computer” it’s in the same place as Start button 🙂 and choose YaST. You’ll be asked for admin password, you entered while installing the system.

Now in the Filter field, type “Install”. Choose “Software Management” from the available programs at right. Now, when Package Selection dialog opens, type “apache”, you’ll find apache2. Select it and click Install. Apache will move to the right column. Optionally, you can install also prefork and utils packages.

Now hit “Apply” to install it. Within two minutes, you’ll be asked to log off and log on. Do it.

By now apache is not running, you should run it and set it starts automatically. To do this, enter terminal window (you can either do it from “Computer” menu or right clicking desktop).

You need elevation to administrate startup programs. So type: “su –“ and enter your password. Terminal color turns red. Type “chkconfig apache2 on”. Now you should check whether it done, so type: “chkconfig apache2 –list”. You should see “On” near number 3 and 5.

To run apache manually, just type “/etc/init.d/apache2 start” to stop “/etc/init.d/apache2 stop”, to restart “/etc/init.d/apache2 restart” and to check the status “/etc/init.d/apache2 status

We done, apache is up and running. Now we should install mono

Mono installation

Start with the same YaST but this time, type “mono” – you’'ll get a lot of programs. To simplified installation, choose (or type) mono-complete. This will all available Mono modules.

After Mono will be installed, you should install also apache2-mod_mono to make possible running ASP.NET mono pages in Apache. do this.

Log off – log on and move to configuration

Mono configuration

Now it’s time to configure what ASP.NET pages you want to run. We want ASP.NET 2.0, so we should run mono apache mode for this version. To do this, go to the terminal, elevate yourself (su –) and type following: “vi /etc/apache2/httpd.conf” This will open VI editor with apache configuration file in it.

Now it’s time to learn VI a little. To start editing, you should type “A” – it will write “INSERT” in the lower left corner. To return to the command mode, hit escape key. To save (from command mode) “:w” to exit and save:wq” to exit without save:q!”. To find/” and string the pattern you are looking for.

Now go the the very end of the file  and write under Include “/etc/apache2/vhosts.d/*.conf” following:
(to short string “[D]” is your virtual directory (slash blank is root), “[P]” is physical path to your site without trailing slash)

MonoServerPath default /usr/bin/mod-mono_server2
Alias [D] “[P]”
AddMonoApplications default “[D]:[P]”
<Location [D]>
SetHandler mono

So, if your site is MySite and it is in /srv/www/htdocs/MySite, this section will looks as following:

MonoServerPath default /usr/bin/mod-mono_server2
Alias /MySite “/srv/www/htdocs/MySite”
AddMonoApplications default “/MySite:/srv/www/htdocs/MySite”
<Location /MySite>
SetHandler mono

If you want to turn it to the root site, this will looks following:

MonoServerPath default /usr/bin/mod-mono_server2
AddMonoApplications default “/:/srv/www/htdocs/MySite”
<Location />
SetHandler mono

Now, we’ll add mono administrative site to be able to restart mono only without touching apache itself. To do this, after last </Location> you should add following:

<Location /mono>
SetHandler mono-ctrl
Order deny,allow
Deny from all
Allow from

I think it’s very clear what it did 🙂

If you have more, then one site and want to configure mono differently for each one of those, you should add VirtualHost section. To do this, include your configuration in to

<VirtualHost [IP and port you want, for example or *:80 for all IPs on port 80]>
ServerName [Name you want]


We done. Restart apache and enter the url you set (for example http://localhost/MySite/)

Working? Good. You finished.

Not working (familiar yellow error 500 screen)? Keep reading…

Debugging Mono website

Do you remember, that you have no development environment in this machine? You can install it, or download Mono liveCD with openSuse. But before doing it, please note, that GTK# (it’s devenv) is not very user friendly. It even worse, then Eclipse. So let’s try to understand first whether we can fix small compatibility problems without entering code.

The most convenient method to debug web site on Mono is by using XSP and XSP2 mini web servers. Just enter the directory of the site and run it. By default you’ll be able to access the site by using “http://localhost:8080” (it also be written for you). Enter and notice whether you have any errors in console. No? Keep doing

The most common problem is “error 500” with nonsense stack. If it contains ScriptManager error Type not found, the problem is in Web.config file. Try to regenerate it to be compatible to Mono (for example, Mono has different version of System.Web.Extensions assembly. In ASP.NET 3.5 it has version 3.5, Mono has only 1.0.61025.0 (the old AJAX.NET). To recreate your web.config all you have to do is to execute “mconfig af AJAX Web.config” It will create default web.config file, supports System.Web.Extensions (AJAX features).

Not helped? Keep doing. Let’s look another time into the stack – if it contains errors in “EnablePageMethods” or “ShouldGenerateScript” or “EncryptString” – the problem is serialization. Mono has very limited support for JSON, XML and SOAP serialization. Try to look into your code and notice if you have classes, marked with [Serializable] or you are transferring your own classes by using PageMethods. If so, replace it with regular strings (my grandma serialization).

Person p = new Person();
string sstr = string.Format(“{0}|{1}|{2}|{3}”, p.FirstName, p.LastName, p.Age, p.Wage);
return sstr;

var sstr = persons[i].split("|");
var p.FirstName =  sstr[0];
var p.LastName =  sstr[1];
var p.Age =  sstr[2];
var p.Wage =  sstr[3];

Not helped? Try to rename “Bin” directory into “bin” “mv Bin bin –r”. Actually this was fixed in latest versions of Mono, but who knows?…

No? Check whether you have partial classes, which is not supported by Mono. If so, recompile it like this

mcs /t:library /out:bin/test.dll –r:System.Web –r:System.Data –r:System.Web.Services –r:System.Web.UI.Controls test.aspx.cs

If you have Generics in your code, you should use gmcs, rather then mcs.

Not helped? It looks, that you have to either install Mono on your Windows machine and debug your code with it. Or, alternatively install GTK# and do in on Linux.

But wait, before doing such big step, install and check the binary compatibility of your code. To do this, you need “Moma” – a simple tool, that tell you if everything is ok for Mono in your assemblies.

Good luck and see you in my forthcoming TechEd session, where I’m presenting openSuse, running UDP multicast server with ASP.NET 3.5 extended methods (It uses recompiled ISAPI filters for apache, rather then regular limited AJAX support in Mono)

Have a nice day and be good people.

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

8 תגובות

  1. jpobst24 ביולי 2008 ב 22:04

    gmcs is not just for generics, it is the 2.0 version of Mono's C# compiler, so you need to use it for any app that you want to target the 2.0 runtime. It has full support for C# 2.0 features, including partial classes (and now also has full support for C# 3.0 features :).

    GTK# is the C# wrapper around the GTK+ toolkit, like Winforms is the C# wrapper around the Win32 toolkit. The development IDE you are referring to is called MonoDevelop.

  2. Tamir Khason25 ביולי 2008 ב 0:27

    Thank you for clarifications, jpobst
    Yes, I meant MonoDevelop, but it still not very user friendly 🙂

  3. Alfred28 ביולי 2008 ב 9:48

    I have an appl developed with Microsoft Visual Studio 2005, runnin gon Windows 2003 with MS SQL.

    Is it possible to port it to linux (with not many modifications)?

  4. James Hancock30 ביולי 2008 ב 14:47

    Getting this running on Windows:

    Program Features/Windows Features/Check off IIS.

    Run management console app for IIS if you really want to make changes but you don't have to.

    You're done, with not a text file to edit, not a configuration to get exactly right, and not a line entered into a command prompt.

    I rest my case about Linux: If you have lots of time and nothing better to do, you can get to where you want to go, but why would you bother? (cost is not a reason, because at the end of the day they cost about the same after one year)

  5. safwan5 בספטמבר 2008 ב 13:28

    I have been involved with mono for about two years now. My experience can be described as painful. Why I am using mono then? the answer is, I have learned programming with Microsoft using visual studio from 2003 up till 2008 and mastered and C#. while I am learning Linux and UNIX systems, I found programming simple GUI applications in linux requires learning C++ or possibly C. So in order for me to start programming in linux, I will completely have to change my style and attitude towards programming which requires learning another programming language such as java, and dealing with bash very often. I am planing to learn C++ and Java for the future but not now. Thanks god, I have start to understand mono and I found it really a great step towards cross platform development. The real strength in the mono project is the side of it. 99% of the codes for microsoft will work on apache linux using the mod-mono (mono-server2), mono-develop xsp server. The story is a bit different in the system level for one reason, and that is using windows forms is different to using gtk# as windows uses a co-ordinate to position element while gtk using a tree style, for example to position an element say for example a textbox then you will have to place it inside a container such as hbox.

    My advice to those who came from the windows world is as follows:

    1- Windows and linux are two different species, Don't expect everything in the dotnet will be supported in linux specially at the system level
    2- understand bash or any fav shell, because it is the main interface you will be dealing with unlik windows everything is a click of a button.
    3- comming from an ide such as visual studio to the ide mono develop requires great understanding of the preferred language for example visual studio makes things easier and does a lot of things behind the seine so the developer is focused on the visual aspect of it while mono-develop requires you to do a bit more. for example adding a text box in mono develop requires you declaring it manually in the code behind if it is going to be used to send input to a function while visual studio put it this
    take the textbox and position it in the windows(form)
    double click , and you automatically find yourself in the code behind page and the click event is written by default(handy for button).
    4- mono project is worth learning

    Here is a a tutorial i have written to help others avoid frustration.
    I am not claiming it is 100% correct but it will work (i hope)
    if you want to participate, add , or correct some of the information so please follow the link in the website (contact safwan).

    What makes mono difficult is the availability of information and documentation is poor

  6. Grayson Peddie13 בספטמבר 2008 ב 11:01

    Very good information and I came from the Windows world and still want 2.0, as I can't afford Windows Server 2003 or 2008, even a Small Business Server… 🙁

    I found myself more productive and comfortable with C#/ than with C++/PHP.

    The reason for choosing Mono is I wanted to be able to have applications communicate via .net when it comes to writing my own home automation server/application.

  7. linux23 בנובמבר 2008 ב 3:39

    re: Configuring and running Mono ASP.NET 3.5 (AJAX.NET) on Linux computers

  8. linux23 בנובמבר 2008 ב 3:39

    re: Configuring and running Mono ASP.NET 3.5 (AJAX.NET) on Linux computers