Running ASP.NET Applications in Debian and Ubuntu using XSP and Mono

Mono is an open-source project providing the necessary software to develop and run .NET client and server applications on Linux, Solaris, Mac OS X, Windows, and Unix. Monodevelop is probably the best IDE for developing .NET applications on Linux. In order to install and use it for development, you will also need the Mono .NET runtime environment installed.

Mono has a fully functional implementation of ASP.NET. This includes full support for ASP.NET Web Forms and Web Services. This essentially means that more or less any ASP.NET application that you have developed using with the .NET Framework will work with Mono. Obviously there might be changes needed, such as data access changes, removal of any
reliance on .NET Framework BCL types that are not implemented in Mono yet, and also the removal of any code that makes
use of platform invoke and so on. At this stage the ASP.NET support in Mono can be considered as excellent and a lot of
publicly available web applications already make use of Mono’s ASP.NET support.

when using ASP.NET with Mono you have two options as regards which web server to host your ASP.NET applications that is XSP and Apache we are using here XSP.

XSP

XSP is a “light-weight web server” capable of hosting and serving ASP.NET applications. It is written using C#, making extensive use of the classes in the System.Web namespace.XSP web server runs on both the Mono runtime and also on the .NET runtime.

Now we are going to take a look how to install XPS and mono for ASP.NET applications and testing this setup

First thing is you need to install mono

Install mono in Debian

If you want to install mono in your debian system you need to run the following command

#apt-get install mono mono-gmcs mono-gac mono-utils monodevelop monodoc-browser monodevelop-nunit monodevelop-versioncontrol

You can can see in this screen which will install all the required packages

Install mono in Ubuntu

If you want to install mono in your Debian system you need to run the following command

sudo apt-get install mono mono-gmcs mono-gac mono-utils monodevelop monodoc-browser monodevelop-nunit monodevelop-versioncontrol

Install XSP Web server in Debian

If you want to install ASP.NET2.0 version use the following command

#apt-get install mono-xsp2 mono-xsp2-base asp.net2-examples

If you want to install ASP.NET1.0 version use the following command

#apt-get install mono-xsp mono-xsp-base asp.net-examples

This will install all the required development environment and sample applications

Install XSP Web server in Ubuntu

If you want to install ASP.NET2.0 version use the following command

sudo apt-get install mono-xsp2 mono-xsp2-base asp.net2-examples

If you want to install ASP.NET1.0 version use the following command

sudo apt-get install mono-xsp mono-xsp-base asp.net-examples

This will install all the required development environment and sample applications for ASP.NET

Test ASP.NET Applications

We have already installed sample applications

If you want to run ASP.NET 2.0 application you need to go to /usr/share/asp.net2-demos/ run the following command

#xsp2

This will start the XSP with ASP.Net 2.0 application

xsp2
Listening on port: 8080 (non-secure)
Listening on address: 0.0.0.0
Root directory: /usr/share/asp.net2-demos
Hit Return to stop the server.
Application_Start

Now you need to point your web browser to http://localhost:8080/

You should seen the following screen

If you want to run ASP.NET 1.0 application you need to go to /usr/share/asp.net-demos/ run the following command

#xsp

This will start the XSP with ASP.Net 1.0 application

xsp
Listening on port: 8080 (non-secure)
Listening on address: 0.0.0.0
Root directory: /usr/share/asp.net-demos
Hit Return to stop the server.
Application_Start

Now you need to point your web browser to http://localhost:8080/

You should seen the following screen

If you want to know more options available for XPS check here

Possible errors

If you get the following error when you point http://localhost:8080/

Error Message: HTTP 404. File not found /usr/share/asp.net2-demos/index2.aspx

Solution

You need to copy the index.aspx to index2.aspx

For Debian Users

#cp /usr/share/asp.net2-demos/index.aspx /usr/share/asp.net2-demos/index2.aspx

For Ubuntu Users

sudo cp /usr/share/asp.net2-demos/index.aspx /usr/share/asp.net2-demos/index2.aspx

Sponsored Link

21 thoughts on “Running ASP.NET Applications in Debian and Ubuntu using XSP and Mono

  1. Hi,
    Great sample I am using Ubuntu and this helped a lot. My issue is that when I try to run the http://localhost:8080/ I Get the following:
    Server error in ‘/’ application
    File ‘/’ not found.
    Description: Error processing request.

    Error Message: HTTP 404. File ‘/’ not found.

    I also used the sudo cp /usr/share/asp.net2-demos/index.aspx /usr/share/asp.net2-demos/index2.aspx
    with same results.
    Any help would be appreciated

    Thanks
    David…….

  2. Another option is the Neokernel, there is a release for Mono of the
    Neokernel Web Server at http://www.neokernel.com, it’s easier to run ASP.NET with
    the Neokernel than with XSP or apache/mod_mono.

  3. To David:
    — i think i’m late on posting this 🙂
    You must be on the directory /usr/share/asp.net2-demos/ before you run xsp. Otherwise that error will be displayed.
    Please take note this when you run xsp, you should see the Root directory: /usr/share/asp.net2-demos/
    HTH.

  4. Hi all. First of all, thank you for this excellent tutorial. I have an asp.net 2.0 app that I used to run on IIS but I am trying t get it to work on Ubuntu with Apache. However, this app uses an MS access database and I cant put xsp to work with this. Any ideas?

  5. To pepesmith: Your solution worked perfectly fine for me. Thanks 🙂

    I am getting index2.aspx not found error now.

  6. It’s working now!!! Here is the solution for Ubuntu users:

    sudo cp /usr/share/asp.net2-demos/index.aspx /usr/share/asp.net2-demos/index2.aspx

    I got this solution from a blogger in another site.

  7. I installed Ubuntu 7.10 with PHP and mySQL and also installed mono for ubuntu (both, xsp1 and xsp2) with examples/demos.
    When running xps or xps2 I seem to get the predicted responses.
    However when going to http://localhost:8080/ the following is displayed in the browser in either case:

    Server Error in ‘/’ Application
    File ‘/’ not found.

    Description: Error processing request.

    Error Message: HTTP 404. System.Web.HttpException: File ‘/’ not found.

    Stack Trace:

    System.Web.HttpException: File ‘/’ not found.
    at System.Web.StaticFileHandler.ProcessRequest (System.Web.HttpContext context) [0x00000]
    at System.Web.HttpApplication+c__CompilerGenerated2.MoveNext () [0x00000]

    12/06/2008 7:44:25 AM

    —————————————

    what went wrong? Mind you, I am also quite new to Linux and ubuntu in particular and can do with all help I can get.

    Cheers, Gerd

  8. I build a website in ASP.net that works perfectly in a windows server. I need to migrate this website to a linux server, which dont have the Mono. I’m going to suggest these application to my co-workers, but i have a doubt: do i have to change anything on my code source? Or the files i have now will just work fine?

    Tks

  9. Server Error in ‘/’ Application
    Standard output has not been redirected or process has not been started.

    Description: HTTP 500. Error processing request.

    Stack Trace:

    System.InvalidOperationException: Standard output has not been redirected or process has not been started.
    at System.Diagnostics.Process.CancelErrorRead () [0x00000]
    at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:CancelErrorRead ()
    at Mono.CSharp.CSharpCodeCompiler.CompileFromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00000]
    at Mono.CSharp.CSharpCodeCompiler.CompileAssemblyFromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00000]
    at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromFile (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00000]
    at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath, System.CodeDom.Compiler.CompilerParameters options) [0x00000]
    at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.CodeDom.Compiler.CompilerParameters options) [0x00000]
    at System.Web.Compilation.AppCodeAssembly.Build (System.String[] binAssemblies) [0x00000]
    at System.Web.Compilation.AppCodeCompiler.Compile () [0x00000]
    at System.Web.HttpApplicationFactory.InitType (System.Web.HttpContext context) [0x00000]

    Version information: Mono Version: 2.0.50727.42; ASP.NET Version: 2.0.50727.42

  10. I got the same problem for normal aspx files on my Debian system.
    I also installed the VNBC compiler with apt-get install.

    A test file with this content started working:
    —-SNIP—-

    TEST
    —-SNIP—-

    I’m wondering why the C# compiler has got such problems while the VB compiler is running well?

  11. Okay, the test file content in my previous commit has been crippled, here again:

    <%@Page language=”vb” %>
    <html>
    <body>
    <%
    Response.Write (“Hello world”)
    %>
    TEST
    </body>
    </html>

  12. try
    sudo find /usr/bin | grep gmcs

    if result is NOT
    /usr/bin/gmcs
    /usr/bin/gmcs2

    try
    1)install mono-gmcs package (if only have “/usr/bin/gmcs”)
    or
    2)in case you have only “/usr/bin/gmcs2” make symlink on it named gmcs
    sudo ln -s /usr/bin/gmcs2 /usr/bin/gmcs

    restart apache2 or xsp or your web server and check result in browser. I think it would help.

  13. hello………..dis is anil……….nd a new user too……..nd m geting following problem……plz help me out….. 🙁

    Server Error in ‘/’ Application
    Mapper type does not implement the ISectionSettingsMapper interface

    Description: HTTP 500. Error processing request.

    Stack Trace:

    System.InvalidOperationException: Mapper type does not implement the ISectionSettingsMapper interface
    at Mono.Web.Util.SettingsMapping.get_MapperType () [0x00000]
    at Mono.Web.Util.SettingsMapping.MapSection (System.Object input, System.Type type) [0x00000]
    at Mono.Web.Util.SettingsMappingManager.MapSection (System.Object input, System.Type type) [0x00000]
    at Mono.Web.Util.SettingsMappingManager.MapSection (System.Object input) [0x00000]
    at System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName, System.String path, System.Web.HttpContext context) [0x00000]
    at System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName) [0x00000]
    at System.Web.Security.RoleManagerModule.Init (System.Web.HttpApplication app) [0x00000]
    at System.Web.Configuration.HttpModulesSection.LoadModules (System.Web.HttpApplication app) [0x00000]
    at System.Web.HttpApplication.InitOnce (Boolean full_init) [0x00000]
    at System.Web.HttpApplication.Start (System.Object x) [0x00000]

    Version information: Runtime: Mono 2.4.4; ASP.NET Version: 2.0.50727.1433

  14. First of all localhost:8080 does not shows xsp home rather it shows apache’s index(var/www).

    Running localhost:8084 gives this (8084 may be the default port in my Ubuntu 11.10, not sure):

    Server Error in ‘/monodoc’ Application
    Argument is out of range. Parameter name: startIndex

    Description: HTTP 400. Error processing request.

    Stack Trace:

    System.ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: startIndex
    at System.String.Substring (Int32 startIndex) [0x00000] in :0
    at Mono.WebServer.MonoWorkerRequest.AssertFileAccessible () [0x00000] in :0
    at Mono.WebServer.MonoWorkerRequest.ProcessRequest () [0x00000] in :0

Leave a comment

Your email address will not be published. Required fields are marked *