Configuring ASP.NET MVC2 on Apache 2.2 using mod_aspdotnet

9,272

Enabling MVC apps on mod_aspdotnet is much easier than that. If you simply add

SetHandler asp.net

to your directory section in order to force all requests through the module. It behaves just like a wildcard mapping in IIS. Since this will process all requests, you'll want to make an exclusion for non-.Net content by adding a location section like this:

<Location ~ "^/MyWebSiteName/Content/.*"> SetHandler none </Location>

Where your Content directory contains all of your image files, css, etc. Alternatively you could write the rule to match a list of file extensions, but I find this easier. The added benefit to this is that you don't have to recode your apps. One other issue that you may encounter is with MVC2 you may not have a default.aspx placehoder to handle your root requests. To deal with use mod_rewrite and added:

  RewriteEngine On
  RewriteBase /MyWebSiteName/
  RewriteRule ^$ Home [R=301]

to my directory configuration which forces redirects the / request to the Home controller.

Share:
9,272

Related videos on Youtube

ChrisQ
Author by

ChrisQ

Updated on September 17, 2022

Comments

  • ChrisQ
    ChrisQ over 1 year

    Trying to get an Microsoft MVC2 website to run on Apache 2.2 web server (running on Windows) that utilizes the mod_aspdotnet module. Have several ASP.NET Virtual Hosts running, trying to add another. MVC2 has NO default page (like the first version of MVC had e.g default.aspx). I have tried various changes to the config: commented out 'DirectoryIndex', changed it to '/'. Set 'ASPNET' to 'Virtual', will not load first page, always get: '403 Forbidden, You don't have permission to access / on this server.'

    Below is from my http.conf:

    LoadModule aspdotnet_module "modules/mod_aspdotnet.so"
    AddHandler asp.net asax ascx ashx asmx aspx axd config cs csproj licx rem resources resx soap vb vbproj vsdisco webinfo
    
    <IfModule aspdotnet_module> 
    
     # Mount the ASP.NET /asp application
     #AspNetMount /MyWebSiteName "D:/ApacheNET/MyWebSiteName.com"
     Alias /MyWebSiteName" D:/ApacheNET/MyWebSiteName.com"
    
     <VirtualHost *:80>
     DocumentRoot "D:/ApacheNET/MyWebSiteName.com"
     ServerName www.MyWebSiteName.com
     ServerAlias MyWebSiteName.com
     AspNetMount / "D:/ApacheNET/MyWebSiteName.com"
    
    # Other directives here
      <Directory "D:/ApacheNET/MyWebSiteName.com">
        Options FollowSymlinks ExecCGI
        AspNet All
       #AspNet Virtual Files Directory
        Order allow,deny
        Allow from all
        DirectoryIndex default.aspx index.aspx index.html
       #default the index page to .htm and .aspx
      </Directory>
     </VirtualHost>
    
     # For all virtual ASP.NET webs, we need the aspnet_client files
     # to serve the client-side helper scripts.
     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
     </Directory>
    
    </IfModule>
    

    Has anyone successfully run Microsofts MVC2 (or the first version of MVC) on Apache with the mod_aspdotnet module? Thanks !

    • Massimo
      Massimo about 14 years
      I'm really curious here: if you're on Windows and if you want to run ASP.NET... why Apache instead of IIS?!?
    • ChrisQ
      ChrisQ about 14 years
      Because IIS requires licenses, Apache is free.
    • Massimo
      Massimo about 14 years
      What do you mean? If you have a Windows license, you're fully entitled to run IIS... there's no additional license needed.
    • ChrisQ
      ChrisQ about 14 years
      XP Home does not come with IIS, Professional on up has it. Many business sites run ASP.NET applications on Apache (usually on Linux) to save costs.
    • Massimo
      Massimo about 14 years
      Agreed. But I really don't see the point in doing that on a Windows server...
    • CP.
      CP. over 13 years
      I second Massimo. When your application grows you anyway need to move it away from Windows XP Home as it is not a server OS. And with any Microsoft server OS you get IIS for free.
    • MatteS
      MatteS over 11 years
      Could a reason for doing this be to, instead of having to install your shipped web based product into an existing iis installation, actually ship your product with a preconfigured web server? (Something we'r considering because of alot of hassle with supporting different IIS versions)