asp.net-mvc-4 – 使用asp.net MVC4,如何在默认情况下执行root index.html?
发布时间:2020-05-25 12:11:36 所属栏目:asp.Net 来源:互联网
导读:对于我的大部分网站,我希望正常路由以MVC方式发生.但是,当应用程序首次启动时,我不希望路由转到/Home/Index.cshtml.我希望它简单地转到/Index.html 我目前的RegisterRoutes看起来像这样(并没有实现我的目标) public static void RegisterRoutes(RouteCollecti
|
对于我的大部分网站,我希望正常路由以MVC方式发生.但是,当应用程序首次启动时,我不希望路由转到/Home/Index.cshtml.我希望它简单地转到/Index.html 我目前的RegisterRoutes看起来像这样(并没有实现我的目标) public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("index.html");
routes.MapRoute(
name: "Default",url: "{controller}/{action}/{id}",defaults: new { controller = "Home",action = "Index",id = UrlParameter.Optional }
);
}
解决方法public ActionResult Index() {
string FilePath = Server.MapPath("~/index.html");
// You can add other conditions also here
if (System.IO.File.Exists(FilePath)) {
return File(FilePath,"text/html");
}
return View();
}
希望这可以帮助! (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
