Thursday, July 1, 2010

Running ASP.NET websites on Apache 2.2


I was running a VPS hosting for a few years. The problem with it is lack of latest technologies I would to play with. And of course - as we have the hosting mainly for fun I would not pay a lot.
Originally the VPS was preinstalled with .NET 2.0 framework. During years I have upgraded it to .NET 3.5 but at the end I was almost out of free space and I was still missing upgraded SQL Server.
So I was thinking how to solve it. At home I had an old notebook with installed Windows XP Professional.
Unfortunatelly on Windows XP can't be hosted multiple domains under built-in IIS server.
When I was testing the module, I have found that there is a problem with support of multiple cookies set from ASP.NET application. Fortunatelly there is also a patch available for it - but you must recompile the mod_aspdotnet module.


System setup

  • Windows XP SP2
  • MS SQL Express 2005
  • Apache 2.2
  • Mail Enable SMTP server
  • 2 domains, 5 subdomains (ASP.NET 2.0 applications and MVC 1.0 applications)

Apache installation

I installed Apache using it's default settings with the only one exception - I enabled development components for installation. It was because I was recompiling mod_aspdotnet module.

Module compilation

I recompiled the mod_aspdotnet because of a bug in support of multiple cookies. Here is available patch for this bug, but at the meantime it wasn't integrated into the sources.

Installation is quite simple. In the root of the source tree is available a batch file () which will show you how to manually install the compiled binaries.

Apache configuration

Apache configuration is very simple and straightforward - an example which allows multiple virtual servers and Microsoft MVC for ASP.NET follows (more information can be found on the modules home page):
LoadModule aspdotnet_module modules/ 
LoadModule rewrite_module modules/

AddHandler asax ascx ashx asmx aspx axd \ 
           config cs csproj licx rem resources resx \ 
           soap vb vbproj vsdisco webinfo 

AliasMatch /aspnet_client/system_web/(\d+)_(\d+)_(\d+)_(\d+)/(.*) "C:/Windows/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4" 
<Directory "C:/Windows/Microsoft.NET/Framework/v*/ASP.NETClientFiles"> 
  Options FollowSymlinks 
  Order allow,deny Allow from all 

NameVirtualHost *

<VirtualHost *> 
  DocumentRoot c:/webroot/
  ErrorLog "logs/
  AspNetMount / "C:/webroot/"
# folders which shouldn't be handled thru
# (see SetHandler in Directory definition)
  <Location ~ "/(Content|Scripts)">
    SetHandler None
  <Directory "C:/webroot/">
    RewriteEngine On 
    RewriteBase /
# redirect to the default location
    RewriteRule ^$ /Default.aspx [R=301]
# handle all files in directory thru the Asp.Net
    Options FollowSymlinks Indexes
    AspNet All
    Order allow,deny
    Allow from all
    DirectoryIndex Default.aspx