Update Sep 18, 2016: This was my very old article. It might not work anymore. And it is obsolete with today technology. Please use other technology rather than using this. Thanks.
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):
- 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
- 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.
- Save the file and restart your Apache.
- 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" %> <html> <head> <title>First Mono ASP.NET Application</title> </head> <body> <form runat="server"> Enter your name: <asp:TextBox id="name" runat="server" /> <asp:Button id="greet" Text="Greet" onClick="OnGreetClick" runat="server"/> </form> <strong><asp:Label id="message" runat="server">Hello, World! </asp:Label></strong> </body> <html>
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; } } }
- Ok now save file to your web server. Mine is at the /var/www/firstaspnet/
- 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.
Why would you want to? There are far, far more adept tools already available on *nix without that and its included non-native bloat. Plus .NET/Mono is not known for standards compliance or producing good code.
All in all, this is a stupid idea.
Hi Rob,
In my case, i have an ASP.Net application and only have a Linux Server. And need to deploy as soon as possible. So i think mono would be the quick and dirty solution for that. Rather than i rebuild it into java project.
Thanks it helps!
Why would you want to? There are far, far more adept tools already available on *nix without that and its included non-native bloat. Plus .NET/Mono is not known for standards compliance or producing good code.
All in all, this is a stupid idea.
Hi Rob,
In my case, i have an ASP.Net application and only have a Linux Server. And need to deploy as soon as possible. So i think mono would be the quick and dirty solution for that. Rather than i rebuild it into java project.
Hi Ivan. First, thanks for the straight forward tutorial. It is sad that some are jealous and angry about their lack of skills or knowledge. I’m not hating on all beginners. a beginner who will soon achieve greatness will ask intelligent questions and learn from people who have the knowledge they seek. These people are already in the right mindset.
Then you have the amateurs out there that will try to sound intelligent by BSing and putting others down, They are unlikely to learn anything. And don’t worry, the people out there who know what they are doing can instantly spot those people and know they are just bitter wannabes who lack the brain power to even learn enough to one day make quality comments. Just ignore these people. The people who actually have experience can see right through them.
Yes how stupid. why would anyone want to develop tools to allow you to port .net and other applications from expensive IIS servers to cheap / free linux servers …..
Yes how stupid. why would anyone want to develop tools to allow you to port .net and other applications from expensive IIS servers to cheap / free linux servers …..
Because he must 🙁
Because he must 🙁
I have a (probably stupid) question- if the hosting company on whose linux servers i'm hosting my page is using mono, do i have to configure something in my asp.net project or it should work already?
Hi Alex,
No you don't have to. Just upload to the server and it's ready to run.
I have a (probably stupid) question- if the hosting company on whose linux servers i’m hosting my page is using mono, do i have to configure something in my asp.net project or it should work already?
Hi Alex,
No you don’t have to. Just upload to the server and it’s ready to run.
Thanks!
Thanks!
Does this also works for vb language
Works great! Very simple, concise directions! One small glitch: In step 5, you save BOTH files to the target directory, not just one.
Another answer to some who ask why run .NET on Linux: Being knowledgeable in areas across disciplines is critical to long term career success in IT. Being able to make very different systems talk to one another, or to write applications in .NET, Java for desktops, servers or even embedded applications makes you very employable in this economy.
Cheers!
Hi Ivan,
Thanks for the useful Article.
If I have a compiled asp.net application (I mean just some .aspx empty files and a /bin folder full of .dll), does it run as well on linux with your manual?
Regards,
-T
Hi your sample link is just the code , not running.
Hi i'm sorry for that.
Before i was host on my friend VPS, and i installed Mono there.
But now i move to shared hosting, that's doesn't have Mono. So the code won't running.
But it used to work.
Thank you sooo much, this is the only guide that actually worked for me! i got it working in a few minutes, instead of beating my head against the ground following other peoples tutorials!
Same here, top notch job !!
Thanks mate.
Glad to hear that 🙂
I want to run dotNET application on RHEL 5. Iam unable to get all the packages for apache2-mod_mono. Plz Help…
Thank You
Please provide me the link from where i can download all the required packages.
try to update your yum source list.
i haven’t play with rhel 5 for a while.
I want to run dotNET application on RHEL 5. Iam unable to get all the packages for apache2-mod_mono. Plz Help…
thanx…..
have you tried to update your repository?
Thanks that worked for me………………
really nice article………
why do not work in firefox and chrome.
these http clients show resource code.
pls help me?
It's not your browser. It is your apache configuration.You need to add apache handler for your aspx script. otherwise it will consider as text.
I'm new at this, can you what handler should I write for .aspx extension?
ty
I installed mono tools for visual studio… I have prepared a application on asp.net. But i have hosting space of APACHE server. Can i upload my aspx files there. Please help me
Hello! When I go on my web page I get source code text and NOT web page. Can somebody tell me how to solve this? Thanks!
@martinopresnik It is because your web server doesn’t have the handler for you aspx file. You should install mono and add the correct handler for your aspx file.
@ivankrisdotcom I DID THIS TOOOOOO. But still NOT WORKING
Very nice article thanks, I tried it and it worked, it would be great if you can update it for mono 2.8.
Thanks for the article.
If you want asp.net 4.0 then also do:
sudo apt-get install mono-apache-server4
in your mod_mono.conf put the following:
AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascxDirectoryIndex index.aspxMonoAutoApplication enabledMonoServerPath "/usr/bin/mod-mono-server4"
Oh, and if you want to give yourself access to change files in the /var/ww directory, do:
cd /var/www
sudo chown -R root:www-data .
usermod -a -G www-data <yourusername>
Oh, and if you want to give yourself access to change files in the /var/ww directory, do:
cd /var/www
sudo chown -R root:www-data .
sudo chmod -R 774 .
sudo usermod -a -G www-data <yourusername>
Thanks for posting this. I will be great if you can also post tutorials about this web server you’re using in Linux, specifically in handling ASP.NET Websites like what we deal with using ISS.
Thanks!
Hello Indra, it clear says that the web server is using Apache.
what was sestatus then?
I am working on same thing, having trouble in SELinux and mono configuration.
My .aspx loads when selinux is disabled; and can’t when it is disabled or permissive.
Really wish google wouldn’t put obsolete articles at the very top of search results. Most of these packages are obsolete or unavailable