ASP.NET MVC 在 IIS 6 上

由於 ASP.NET MVC 使用新的 URL 格式, 不以 .aspx 當成附檔名, 當 ASP.NET 佈署到 IIS 6 時, IIS 6 無法自動辨識什麼樣的 URL 才需要轉交給 ASP.NET 引擎執行, 我們必需手動設定 IIS 6, 讓 ASP.NET MVC 可以正確執行。

https://www.asp.net/learn/mvc/tutorial-08-cs.aspx 介紹一種使用 ISAPI extension 的方式, 先在 IIS 6註冊一個 .mvc 的附檔名轉交到 ASP.NET, 然後修改 ASP.NET MVC 的 URL 路徑, 讓 ASP.NET MVC 的 URL 有 .mvc 的路徑。

1. 修改 ASP.NET MVC 的 URL 格式

Global.asax.cs 檔:

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

            routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);

        }

 

 

2. 在 IIS 6 新增 .mvc

image image image

執行檔(X): c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll

副檔名(E): .mvc

限於為(L): GET,HEAD,POST,DEBUG

不要選"確認讓檔案是否存在(V)"

image