Mono MVC 2 home route doesn't work
I'm trying to convert an ASP .NET MVC 2 app to run on nginx/mono 2.8. So far it seems to work quite well except that the default route doesn't work when the path is empty. I am proxying all requests through to the fastcgi server and I get served up with an ASP .NET 404 not found page.
i.e. This doesn't work
http://mysite.com
But this does
http://mysite.com/home
My Global.asax.cs file looks like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace MyProject
{
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Default route
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Inde开发者_如何转开发x", id = UrlParameter.Optional }, // Parameter defaults
new string[] {"MyProject.Controllers"}
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
}
}
EDIT: Some more info on my setup. I am running OS X 10.6 if that makes any difference. Also the same problem exists for the default route of any areas in the MVC project.
I actually ran into the same problem and solved it (at least in my situation) by complete mistake...
In the nginx walkthrough on the mono project's site, it says to enter these lines in your nginx.conf file:
index index.html index.htm default.aspx Default.aspx;
fastcgi_index Default.aspx;
Well, I set this up in the exact same way (or so I thought) on two VMs. Problem is, one VM had it's root url work and one didn't. What it turned out to be was that I forgot the semi-colon on the 'index' line on the VM that worked, so that the 'fastcgi_index' line was interpreted as part of the 'index' line.
So on the VM that didn't work, I removed that semi-colon. And guess what? It worked. So then I added the semi-colon and entirely removed the 'fastcgi_index' line and it still worked. So based on this anecdotal evidence and some guess work, I'd say that the 'fastcgi_index' line should not be included in MVC applications. Well, at least MVC 3, I haven't tested anything else.
Did you follow the nginx configuration from this page?: http://www.mono-project.com/FastCGI_Nginx
My guess would be the default document is getting in the way.
精彩评论