# apache & mod_mono (asp.net)

## zambizzi

I'm trying to run some of the web apps I developed in C# for asp.net (.net framework 1.1) on Mono/mod_mono but am thus far having no success.

I've added the "-D MONO" flag in /etc/conf.d/apache2 and everything appears to be configured correctly...I guess.  XSP is running w/o error...and apache has given me no clues (nothing in error_log about this).

Here's what I get:

http://zambizzi.net/index.aspx

"Service unavailable..."

I'm using the following combination:

Apache 2.0.53

Mono 1.1.6 

mod_mono 1.0.6

Here's my mod_mono config:

```

<IfDefine MONO>

        # Set this to False if you manage your ASP.Net server through

        # /etc/init.d/mod-mono-server

        MonoRunXSP False

        <IfModule !mod_mono.c>

                LoadModule mono_module modules/mod_mono.so

        </IfModule>

        <IfModule mod_mime.c>

                AddHandler mono .aspx .ashx .asmx .ascx .asax .config .ascx

        </IfModule>

### please also add "-D MONO_DEMO" in order to activate out-of-the-box mono demo

###

        <IfDefine MONO_DEMO>

                <IfModule mod_alias.c>

                        Alias /mono "/usr/share/doc/xsp/test"

                </IfModule>

                MonoApplications "/mono:/usr/share/doc/xsp/test"

                <Directory /usr/share/doc/xsp/test>

                        <IfModule mod_access.c>

                                Order allow,deny

                                Allow from all

                        </IfModule>

                        <IfModule mod_dir.c>

                                DirectoryIndex index.aspx

                        </IfModule>

                </Directory>

        </IfDefine>

### MONO_DEMO end.

</IfDefine>

```

If you noticed this at the top of the config:

```

        # Set this to False if you manage your ASP.Net server through

        # /etc/init.d/mod-mono-server

        MonoRunXSP False

```

Since I'm running XSP, should this be set to true?  I don't have a "mod-mono-server" in my /etc/init.d so I'm not sure what that is...couldn't search it in portage either...any clues there?

I realize that the Mono & mod_mono ebuilds I'm using are hard-masked but I get the same exact results w/ the current "stable" version so I'd rather use the latest to get some of the .NET 2.x features, if possible.

Can anyone help me out?

Thanks!

EDIT:

I set the MonoRunXSP line to True, rebooted apache & xsp, and it did not change.

EDIT:

I tried the last two suggestions in this thread w/ no luck:

https://forums.gentoo.org/viewtopic-p-1949269-highlight-xsp.html#1949269

----------

## arch4nge1

Hi,

These are the notes I wrote from setting up basic mono and apache. I apologise for their brevity. Hope they help:-

Getting mod-mono working with Apache2

The following is the /etc/apache2/conf/modules.d/70_mod_mono.conf:-

```

<IfDefine MONO>

  <IfModule !mod_mono.c>

    LoadModule mono_module extramodules/mod_mono.so

#      LoadModule mono_module /usr/lib/apache2-extramodules/mod_mono.so

  </IfModule>

  <IfModule mod_mime.c>

    AddHandler mono .aspx .ashx .asmx .ascx .asax .config .ascx

  </IfModule>

  AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascx

  MonoUnixSocket /tmp/mod_mono_server

  # Uncomment this block to enable the xsp samples

  <IfModule mod_alias.c>

    Alias /mono "/usr/share/doc/xsp/test"

  </IfModule>

  MonoApplications "/mono:/usr/share/doc/xsp/test:/aspnet:/var/www/localhost/htdocs/aspnet"

  <Directory /usr/share/doc/xsp/test>

    SetHandler mono

    <IfModule mod_access.c>

        Order allow,deny

        Allow from all

    </IfModule>

  </Directory>

  <Location /mono>

       SetHandler mono

  </Location>

  <IfModule mod_alias.c>

       Alias /aspnet "/var/www/localhost/htdocs/aspnet"

  </IfModule>

  <Directory /var/www/localhost/htdocs/aspnet>

        Options Indexes

        AllowOverride None

        Order allow,deny

        Allow from 127.0.0.1

        Allow from localhost

        AddHandler mono .aspx .ascx .asax. ashx .config .cs .asmx

  </Directory>

  <Location /aspnet>

       SetHandler mono

  </Location>

</IfDefine>

#AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascx

#MonoUnixSocket /tmp/mod_mono_server

#LoadModule mono_module /usr/lib/apache2-extramodules/mod_mono.so

#MonoApplications "/var/www/localhost/htdocs/aspnet:/usr/share/doc/xsp/test"

#<Directory "/usr/share/doc/xsp/test">

#        Options Indexes

#        AllowOverride None

#        Order allow,deny

#        Allow from 127.0.0.1

#        Allow from localhost

#        AddHandler mono .aspx .ascx .asax. ashx .config .cs .asmx

#</Directory>

#Alias /mono "/usr/share/doc/xsp/test"

#<Location /mono>

#        SetHandler mono

#</Location>

<IfDefine MONO>

  <IfModule mod_mono>

    ProxyPass /mono/ http://127.0.0.1:8079/

    ProxyPassReverse /mono/ http://127.0.0.1:8079/

    Alias /usr/share/doc/xsp/test/ /mono/

  </IfModule>

</IfDefine>

```

Save the following script as /etc/init.d/mono-server

```

#!/sbin/runscript

# Copyright 1999-2003 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Header: /var/cvsroot/gentoo-x86/dev-dotnet/mono/files/dotnet.init,v 1.4 2004/06/25 13:22:20 scandium Exp $

MONO=/usr/bin/mono

#SERVER=/usr/bin/mod-mono-server.exe

SERVER=/usr/bin/mod-mono-server

#ROOT=/usr/share/doc/xsp/test

#ROOT=/var/www/localhost/htdocs/aspx

ROOT=/var/www/localhost/htdocs

#APPLICATIONS=/mono

APPLICATIONS=/

SOCKET=/tmp/mod_mono_server

depend() {

        before apache2

}

start() {

   ebegin "Configuring Mod-Mono.............."

#   echo Running Command:

#   echo $MONO $SERVER --root $ROOT --applications "$APPLICATIONS":.&

#   $MONO $SERVER --root $ROOT --applications "$APPLICATIONS":. --nonstop 1>/dev/null 2>/dev/null &

       $SERVER --root $ROOT --applications "$APPLICATIONS":. --nonstop 1>/dev/null 2>/dev/null &

   FIXED=0

   while [ $FIXED = 0 ];do

#      echo "Waiting for $SOCKET to be created"

      if [ -S $SOCKET ];then

#    echo "Change the owner of $SOCKET"

    chown apache:apache $SOCKET

#    echo "Change the permissions on $SOCKET"

    chmod 666 $SOCKET

     FIXED=1

      fi

      sleep 5

   done

   eend

}

stop() {

   ebegin "Stopping Mod-Mono................."

   PROCESS=`ps -ef | grep 'mod\-mono\-server.exe'`

   #echo "$PROCESS"

   for PID in `echo "$PROCESS" | awk '{print $2}'`;do

      #echo "Killing $PID"

      kill $PID

   done

   if [ -S $SOCKET ];then

      rm /tmp/mod_mono_server

   fi

}

```

Start apache and mono up by doing:-

```

/etc/init.d/apache2 start

/etc/init.d/mono-server start

```

Save the following as test.aspx and place it in /var/www/localhost/htdocs/aspnet

```

<%@ Page Language="C#" %>

<html>

<head>

<title>My First ASP.NET Page</title>

<script runat="server">

 protected void Page_Load(Object Source, EventArgs E)

 {

   TimeLabel.Text = DateTime.Now.ToString();

 }

</script>

</head>

<body>

 

 <p>Hello there!</p>

  

  <p>The time is now: <asp:label runat="server" id="TimeLabel" /></p>

  

</body>

</html>

```

Point the browser to http://localhost/aspnet/test.aspx and if the output is like the following:-

```

Hello there!

The time is now: 03/04/2005 11:14:15

```

then ASP.NET is working on mod_mono. 

Cheers

----------

## qnx

Nobody has yet replied, so I thought it'd be good idea to say thank you! A simple, yet useful howto, followed it and it's working perfectly, thank you! =)

----------

## pkimber

I agree.  The how to works perfectly.  Thanks for your help.

----------

## taskara

could someone please bottle ths guy up? he is gold.

thanks arch4nge1!

----------

## beekman001

Posted on wrong thread

----------

## gtrplr

Hello,

I followed arch4nge1's post exactly. (even cut and pasted parts of it in) When I load the test.aspx up in my browser, I get "Hello there!

The time is now:   "

no time. I have emerged mono and mod_mono in apache2. Could someone help please, I am not sure what details are needed.

----------

## mw007

Hello!

I followed the howto posted above. I don't get any errors, but the pages are not run as they should. When I goto the url: http://localhost/aspnet/test.aspx I get the actual page text (the html and c# code). Any ideas on how I can get this to run?

Thanks in advance!

----------

## Alien_Freak

Is there any way to allow a user to run aspx scripts?  

ie.  http://localhost/~user/script.aspx    or http://localhost/~user/asp/script.aspx?

I'd love to see a tutorial on that....or a howto

----------

## gr0x0rd

I followed arch4nge1's instructions exactly and it worked perfectly. I just had to change the path instances in the 70_mod_mono.conf from extramodules/mod_mono.so to modules/mod_mono.so .

Thank you for this thread!!

----------

