asp.net-mvc-2 – Mono MVC 2主路由不起作用

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-2 – Mono MVC 2主路由不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试将ASP .NET MVC 2应用程序转换为在Nginx / mono 2.8上运行.到目前为止它似乎工作得很好,除了当路径为空时默认路由不起作用.我将所有请求代理到fastcgi服务器,我得到了一个ASP .NET 404找不到的页面.

即这不起作用

  1. http://mysite.com

但这样做

  1. http://mysite.com/home

我的Global.asax.cs文件看起来像这样

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using System.Web.Routing;
  8. namespace MyProject
  9. {
  10. public class MvcApplication : System.Web.HttpApplication
  11. {
  12. public static void RegisterRoutes(RouteCollection routes)
  13. {
  14. routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  15. // Default route
  16. routes.MapRoute(
  17. "Default",// Route name
  18. "{controller}/{action}/{id}",// URL with parameters
  19. new { controller = "Home",action = "Index",id = UrlParameter.Optional },// Parameter defaults
  20. new string[] {"MyProject.Controllers"}
  21. );
  22. }
  23. protected void Application_Start()
  24. {
  25. AreaRegistration.RegisterAllAreas();
  26. RegisterRoutes(RouteTable.Routes);
  27. }
  28. }
  29. }

编辑:
有关我的设置的更多信息.我正在运行OS X 10.6,如​​果这有任何区别. MVC项目中任何区域的默认路由也存在同样的问题.

最佳答案
我实际上遇到了同样的问题并且完全错误解决了它(至少在我的情况下)…

在mono项目的网站上的nginx walkthrough中,它说要在你的Nginx.conf文件中输入这些行:

  1. index index.html index.htm default.aspx Default.aspx;
  2. fastcgi_index Default.aspx;

好吧,我在两个虚拟机上以完全相同的方式(或者我认为)设置了它.问题是,一个VM有它的根URL工作而一个没有.事实证明,我忘记了VM上“索引”行上的分号,因此’fastcgi_index’行被解释为’index’行的一部分.

所以在没有工作的VM上,我删除了那个分号.你猜怎么着?有效.然后我添加了分号并完全删除了’fastcgi_index’行,它仍然有效.因此,基于这个轶事证据和一些猜测工作,我会说’fastcgi_index’行不应该包含在MVC应用程序中.好吧,至少MVC 3,我没有测试过任何其他东西.

猜你在找的Nginx相关文章