3

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 !

flascuba
  • 33
  • 1
  • 4
  • I'm really curious here: if you're on Windows and if you want to run ASP.NET... why Apache instead of IIS?!? – Massimo Apr 24 '10 at 16:23
  • Because IIS requires licenses, Apache is free. – flascuba Apr 27 '10 at 19:00
  • 1
    What do you mean? If you have a Windows license, you're fully entitled to run IIS... there's no additional license needed. – Massimo Apr 27 '10 at 20:00
  • 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. – flascuba Apr 28 '10 at 23:43
  • Agreed. But I really don't see the point in doing that on a **Windows server**... – Massimo Apr 29 '10 at 05:58
  • 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. – Pradeep Oct 11 '10 at 07:45
  • 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) – MatteS Oct 12 '12 at 13:06

2 Answers2

2

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.

  • Where were you 3 weeks ago when I needed you ! :-) Switched over to your idea, removed the .mvc extensions. Put SetHandler and RewriteEngine lines inside of . Put SetHandler None inside of Also, changed to 'RewriteBase /' Removed 'mvc' from 'AddHandler' line, removed 'DirectoryIndex' line. My way was causing asp.net to load the Script and Content files. Had to change/correct 'letter case' in all my paths, asp.net was not case sensitive like Apache is. Works like a charm now, thank you, you BigWetDog! – flascuba May 13 '10 at 13:40
0

A Answer

I am running XP Home with Apache 2.2.10 with NOSSL and MS SQL 2008 Express (Advanced). If you want to know how to get ASP.NET to run on Apache do this first. What I discovered about MVC on web servers was from (http://www.asp.net/learn/mvc/tutorial-08-cs.aspx). (I am a new user and cannot submit with more that one hyperlink, go figure) I choose the .mvc extension option. Below is my configuration:

LoadModule aspdotnet_module "modules/mod_aspdotnet.so"
AddHandler asp.net mvc asax ascx ashx asmx aspx axd config cs csproj licx rem resources resx soap vb vbproj vsdisco webinfo
<IfModule aspdotnet_module> 
 Alias /MyWebSite"D:/ApacheNET/MyWebSite.com"

<VirtualHost *:80>
 DocumentRoot "D:/ApacheNET/MyWebSite.com"
 ServerName www.MyWebSite.com
 ServerAlias MyWebSite.com
 AspNetMount / "D:/ApacheNET/MyWebSite.com"

# Other directives here
  <Directory "D:/ApacheNET/MyWebSite.com">
    Options FollowSymlinks ExecCGI
    #AspNet Files Directories Virtual
    AspNet All
    Order allow,deny
    Allow from all
    DirectoryIndex index.html
    #default the index page to .htm and .aspx
  </Directory>
</VirtualHost>

Added mvc to AddHandler above. I changed the Default route in global.aspx:

routes.MapRoute(
                "HomeIndex",
                "default.mvc", 
                new { controller = "Home", action = "Index" }
                );

routes.MapRoute(
                "Default",
                "{controller}.mvc/{action}/{id}",
                new { action = "Index", id = "" }
                );

Then I made a index.html file that re-directed the incoming root visitor to default.mvc. That's about it.

flascuba
  • 33
  • 1
  • 4