.net从开始

时间:2016-10-31 16:18:53

标签: c# asp.net-mvc

我有页面,哪些内容和网址从数据库更改。但是,我想设置像

这样的网址
  

本地主机:XXXX /我的页面

现在我

  

本地主机:XXXX /页/我的页面

我不需要。我该怎么做才能改变它? 我的路线

routes.MapRoute(
    name: "LandingPage", 
    url: "Pages/{*urltitle}",
    defaults: new { controller = "Admin", action = "LandPage", urltitle = UrlParameter.Optional }
);
routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

我的更改内容和网址代码

public ActionResult LandPage()
    {
      string temp = RouteData.Values["urltitle"].ToString();
            var item = RepositoryManager.Instanse.LandingContentRepository.GetItemByURL(temp);
            IEnumerable<LandingContent> list = new List<LandingContent>() { item };
            ViewBag.HtmlStr = item.HTMLText;
            return View(ViewBag);
    }

1 个答案:

答案 0 :(得分:0)

好吧,我有点解决了 我的最后路线

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
        name: "LandPage",
        url: "{segment}",
        defaults: new { controller = "Home", action = "LandingPage" }

在HomeController中你可以这样做

  [AllowAnonymous]
    public ActionResult LandingPage(string segment)
    {some logic}