使用mod_aspdotnet在Apache 2.2上configurationASP.NET MVC2

试图让一个Microsoft MVC2网站运行在使用mod_aspdotnet模块的Apache 2.2 web服务器上(运行在Windows上)。 有几个ASP.NET虚拟主机正在运行,试图添加另一个。 MVC2 没有默认页面(如MVC的第一个版本,例如default.aspx)。 我已经尝试了对config的各种更改:将“DirectoryIndex”注释掉,将其更改为“/”。 设置“ASPNET”为“虚拟”,不会加载第一页,总是得到:'403禁止,您没有权限访问/在此服务器上。

下面是从我的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> 

有没有人用mod_aspdotnet模块在Apache上成功运行微软MVC2(或第一版MVC)? 谢谢 !

在mod_aspdotnet上启用MVC应用程序比这更容易。 如果你只是添加

 SetHandler asp.net 

到您的目录部分,以强制通过模块的所有请求。 它的行为就像IIS中的通配符映射。 由于这将处理所有请求,因此您需要添加如下所示的位置部分来排除非.Net内容:

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

你的内容目录包含所有的图像文件,CSS等。或者你可以写规则来匹配文件扩展名列表,但我觉得这更容易。 这个额外的好处是,你不必重新编码你的应用程序。 你可能遇到的另一个问题是MVC2你可能没有一个default.aspx placehoder来处理你的根请求。 处理使用mod_rewrite并添加:

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

到我的目录configuration强制redirect到/ home控制器/请求。

答案

我用Apache 2.2.10与NOSSL和MS SQL 2008 Express(Advanced)运行XP Home。 如果您想知道如何让ASP.NET在Apache上运行,请首先执行此操作 。 我发现有关Web服务器上的MVC的是( http://www.asp.net/learn/mvc/tutorial-08-cs.aspx )。 (我是一个新用户,不能提交更多的超链接,去图)我select.mvc扩展选项。 以下是我的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> 

在上面的AddHandler中添加了mvc 。 我更改了global.aspx中的Default路由:

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

然后我创build了一个index.html文件,将传入的根访问者redirect到default.mvc。 就是这样。