Asp.net-Mvc-2
Mono MVC 2 主路由不起作用
我正在嘗試將 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項目中任何區域的預設路由也存在同樣的問題。
我實際上遇到了同樣的問題並完全錯誤地解決了它(至少在我的情況下)……
在 mono 項目站點上的nginx 演練中,它說在 nginx.conf 文件中輸入這些行:
index index.html index.htm default.aspx Default.aspx; fastcgi_index Default.aspx;好吧,我在兩個虛擬機上以完全相同的方式(或者我認為)進行了設置。問題是,一個虛擬機有它的根 URL 工作,而一個沒有。結果是我忘記了 VM 上有效的“索引”行上的分號,因此“fastcgi_index”行被解釋為“索引”行的一部分。
所以在不起作用的虛擬機上,我刪除了那個分號。你猜怎麼著?有效。然後我添加了分號並完全刪除了“fastcgi_index”行,它仍然有效。所以基於這個軼事證據和一些猜測工作,我會說’fastcgi_index’行不應該包含在MVC應用程序中。好吧,至少 MVC 3,我還沒有測試過其他任何東西。