Asp.net-Mvc

想從 mvc 使用 index.html

  • November 4, 2013

當我載入我的新網站時,我有一些使用 MVC,而另一半使用靜態頁面。

第一頁應該是 index.html

但是,當我訪問http://domain時,它會直接進入 MVC 控制器。

它不會轉到 index.html,即使我有 IIS 指向此頁面,也可能是因為我在 IIS 中使用萬用字元,如我的部落格http://www.bryanavery.co中所述.uk/post/2009/07/02/Deploying-MVC-on-IIS-6.aspx

但是當我選擇http://domain時,我需要第一頁去 index.html

有任何想法嗎?

您可以將路徑指向控制器操作並返回文件,如下所示:

public ActionResult Index()
{
   return File("index.html", "text/html");
}

告訴路由引擎忽略 index.html:

routes.IgnoreRoute("index.html");

引用自:https://stackoverflow.com/questions/1715015