Advertisement

ASP.NET ON LINUX

HTML clipboard

ASP.NET is a powerful web technology provided by Microsoft. It supports multiple languages (like VB, C#) runs on Windows platform using CLR (Common Language Runtime). 

But this technology is proprietary and not open-source. Michael DeIcaza , a famous open-source developer appreciated the merits of asp.net and developed the Mono project. Mono is free and open-source software which can be run both in Windows and Linux. Any C# program compiled in windows can be executed in Linux using mono. A c# program can also be compiled within Linux and run there. Ubuntu gives mono interpreter by default. We need not take any special steps to install mono interpreter. But, if we want to compile the C# file in Ubuntu, we have to install the mono software. This has been described below. For more details about mono, visit www.mono-project.com

Now we see how to run ASP.NET on Linux. Linux and mono are available free. Compared to Microsoft’s visual studio frame work, Mono is very small in size. Mono packages are available in different formats depending upon the distribution of the Linux. For example “*.deb” packages are for Debian and Ubuntu distributions. “*.rpm” packages for Redhat Linux and “.bin” packages for all of the Linux distributions. We can download the packages from www.mono-project.com.

For running ASP.NET with mono, we use the “XSP2” server. This is also available in the same site. 

To install the mono package “mono-1.9.1_2-installer.bin” package, copy the package into “/home/user” directory on Linux and open the terminal window and type,

~$ sudo ./mono-1.9.1_2-installer.bin



Then we have to install the “XSP2 server”, it is available as source file in a zipped format with the name “xsp_2.4.2.orig.tar.gz”. Download it from the same site. Save it in the Desktop, right click, and select “Extract here”. Then copy the extracted directory into “/home/user” directory. And we have to build the source file using the following commands, Open terminal and type,

~$ cd xsp2/
xsp2 ~$ sudo ./configure

Now the xsp2 server will be installed. We should install the xsp2 server after mono has been installed because the server depends on Mono.

We can run .NET files in two ways, one is running without IDE (using Terminal), another one is using IDE. Mono provides the IDE for .NET named “Monodevelop”. Monodevelop installer is also available on the same site. 

If we have Internet connection with Linux, we can install the packages directly from the internet. In Ubuntu open 
System->Administration->Synaptic package Manager and select all the needed packages and install directly from the internet. This method is recommended by Ubuntu developers. 

Now we see how to run a simple ASP.NET program on Linux using IDE. Open Applications->Programming->Monodevelop. The Monodevelop IDE will appear. Open “start a new solution”, enter the project name and select the language which you will use. In our demo, the project name is “hello” and select C#->ASP.NET from the left panel.



Then type the following code into the Default.aspx file on the IDE.

<%@ Page Language="C#" Inherits="hello.Default" %>

<script runat="server">
public void Page_Load()
{
if(!IsPostBack)
{
combo1.Items.Add("VB.NET");
combo1.Items.Add("C#.NET");
combo1.Items.Add("ADO.NET");
combo1.Items.Add("ASP.NET");
}
}

void job1(Object o,EventArgs e)
{
text2.Text="Hello..."+text1.Text;
}

void job2(Object o,EventArgs e)
{
text3.Text="You are selecting..."+combo1.SelectedItem.Text;
}
</script>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Default</title>
</head>
<body bgcolor=green>
<form id="form1" runat="server">
<h1> This is ASP.NET on UBUNTU using MONO</h1>
<br> 
<asp:textbox id="text1" runat="server"/> 
<asp:button onclick="job1" text="click" runat="server"/>
<asp:textbox id="text2" runat="server"/>
<br>
<asp:dropdownlist id="combo1" runat="server"/>
<asp:button onclick="job2" text="click" runat="server"/> 
<asp:textbox id="text3" runat="server"/>

</form>
</body>
</html>


Click the ‘build’ button and then ‘build solution’ button. After building gets successful, press the ‘run’ button. Now the browser will open. It will give the correct result if you follow the above procedure. This is the method for working on the IDE. Now, we see how to work without IDE.



Open Terminal, and make directory for our project,

~$ Terminal->mkdir hello
hello ~$gedit hello.aspx

then type the program on the text editor and save it. Then start the xsp server using the following command,
hello ~$xsp2

XSP server will now start on the default port 8080. It takes the working directory as root directory. Then open the browser, type the url

http://localhost:8080/hello.aspx

If the program is correct, you will get the expected result. Otherwise, the error message will be displayed in the browser. 

ASP.net is a very fine technology, compared to JSF which is similar in purpose.It is very easy to learn. There are very few files in ASP.net, unlike Struts or JSF. As Mono makes the same program to run in either Windows or Linux, porting ASP.net to Linux becomes very easy. Nowadays, due to severe financial crisis in most of the countries, it is more economical to use Linux for web-applications. Mono brings the elegance of
C# and ASP.net to Linux, thereby combining 

Economy & productivity. Moreover, compared to the usual linux languages like php, python and perl and ruby, C# is a compiled language with strong type checking. As pointed out in DeveloperIQ a few months back, architects are switching over to ASP.net with C# in Linux using Mono, for this reason. I will write more about this in future . 

You can reach the author from the following URL. rajeshsoftengr@gmail.com








Added on August 21, 2010 Comment

Comments

#1

Ramya commented, on August 24, 2010 at 10:01 a.m.:

How will i subscribe your magazine. Give me the address.

#2

abhilash commented, on September 3, 2011 at 10:27 a.m.:

Windows created a new problem before the path of the Linux users by the introducing C# and .NET programming criteria, which can be experienced only in the Windows environments. But with Mono, now even Linux users can develop similar applications in Linux environments. In this way, Linux has faced the challenge created before in by Microsoft and became much more stronger than earlier. Mono- .Net Programming C# : ubuntu 11.04

Post a comment