【发布时间】:2010-10-08 15:23:36
【问题描述】:
我正在尝试将 ASP .NET MVC 2 应用程序转换为在 nginx/mono 2.8 上运行。到目前为止,它似乎工作得很好,除了当路径为空时默认路由不起作用。我将所有请求代理到 fastcgi 服务器,并得到一个 ASP .NET 404 not found 页面。
即这不起作用
http://mysite.com
但这确实
http://mysite.com/home
我的 Global.asax.cs 文件如下所示
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 = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] {"MyProject.Controllers"}
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
}
}
编辑: 有关我的设置的更多信息。如果这有什么不同,我正在运行 OS X 10.6。 MVC项目中任何区域的默认路由也存在同样的问题。
【问题讨论】:
-
这样的路线有帮助吗?
routes.MapRoute("Root","/",new { controller = "Home", action = "Index"}) -
是的,添加这样的特定路由确实有效,但我宁愿不这样做,因为 IIS 和 MVC 不需要它。我不确定是 Mono 还是我的 Nginx 设置有问题。
-
同意。这不是你想做的事。
标签: asp.net-mvc-2 routing mono nginx