Create and Run ASP.NET Applications on Linux using Mono



By: Savia Mendes

January 2, 2007 11:01 am

Reads: 953

Comments:0

Rating:0

Problem:

Create and run ASP.NET applications on Linux using Mono.

Solution:

What is Mono?

Mono provides the necessary software to develop and run .NET client and server applications on Linux. It can also be deployed on Solaris, Mac OS X, Windows, and Unix. Mono is dual licensed by Novell, similar to other products such as Qt and the Mozilla Application Suite. Sponsored by Novell, the Mono open source project has an active and enthusiastic contributing community and is positioned to become the leading choice for development of Linux applications.

Some Features

  • Multi-platform
  • Based on the ECMA/ISO standards
  • Runs ASP.NET and Winforms applications
  • Can run .NET, Java, Python and more
  • Open Source, Free Software

Now we come to the main essence of this article, i.e running ASP.NET applications on Linux.

This article assumes that Mono is installed on your Linux system. If it is not installed you can download from http://www.mono-project.com/Downloads

Now, lets get started building our first ASP.NET Application using Mono XSP

First of all let’s create a folder or directory to store the ASP.NET files and change to that directory. You can create the directory in your home directory.

Type in the following commands at prompt to do the same

mkdir aspdotnet 

Will create a directory aspdotnet

cd aspnet 

Will change to directory aspdotnet

Now we will create a simple application that will display a message on click of a button to greet a user who has entered his name in the given text box.

For this we will create a ASP.NET page

Type in the following code in greet.aspx using your choice of Editor (e.g. vi greet.aspx)

Begin of code greet.aspx
<%@ Page language="c#" src="greet.aspx.cs"
Inherits="GreetApp.GreetPage" AutoEventWireup="true" %>
<html>
  <head>
<title>ASP.NET on Linux</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>
<br /><strong><asp:Label id="message" runat="server">Mono Power
</asp:Label></strong>
  </body>
<html>
End of code greet.aspx

Type in the following code in greet.aspx using your choice of Editor (e.g. vi greet.aspx.cs)

Begin of code greet.aspx.cs
using System;
using System.Web.UI.WebControls;
namespace GreetApp
{
   public class GreetPage : System.Web.UI.Page
   {
  protected Label message;
  protected Button greet;
  protected TextBox name;
  public void OnGreetClick(Object sender, EventArgs e)
  {
  message.Text = "Congratulations, " + name.Text + "You are running ASP.NET On Linux ";
  }
   }
}
End of code greet.aspx

After saving the above files, type xsp at the command prompt to start the Server.

xsp 

Now open a web browser, type the url http://localhost:8080/greet.aspx and press ENTER. You should see a web page with a text box and a message. Enter a name in the text box and click the “Greet” button.

Welcome to the world of Mono.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Tags: ,

Disclaimer: As with everything else at NetIQ Cool Solutions, this content is definitely not supported by NetIQ, so Customer Support will not be able to help you if it has any adverse effect on your environment.  It just worked for at least one person, and perhaps it will be useful for you too.  Be sure to test in a non-production environment.

Comment