加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-4 – 使用asp.net MVC4,如何在默认情况下执行root i

发布时间:2020-12-15 20:50:12 所属栏目:asp.Net 来源:网络整理
导读:对于我的大部分网站,我希望正常路由以MVC方式发生.但是,当应用程序首次启动时,我不希望路由转到/Home/Index.cshtml.我希望它简单地转到/Index.html 我目前的RegisterRoutes看起来像这样(并没有实现我的目标) public static void RegisterRoutes(RouteCollect
对于我的大部分网站,我希望正常路由以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();
    }

希望这可以帮助!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读