How can I avoid duplicate content in ASP.NET MVC due to case-insensitive URLs and defaults?

前端 未结 7 1162
无人及你
无人及你 2020-12-24 03:22

Edit: Now I need to solve this problem for real, I did a little more investigation and came up with a number of things to reduce duplicat

7条回答
  •  [愿得一人]
    2020-12-24 04:01

    i really don't know how you are going to feel after 8 years but Now ASP MVC 5 supports attribute routing for easy to remember routes and to solved duplicate content problems for SEO Friendly sites

    just add routes.MapMvcAttributeRoutes(); in your RouteConfig and then define one and only route for each action like

        [Route("~/")]
        public ActionResult Index(int? page)
        {
            var query = from p in db.Posts orderby p.post_date descending select p;
            var pageNumber = page ?? 1;
            ViewData["Posts"] = query.ToPagedList(pageNumber, 7);         
            return View();
        }
        [Route("about")]
        public ActionResult About()
        {
            return View();
        }
        [Route("contact")]
        public ActionResult Contact()
        {
            return View();
        }
        [Route("team")]
        public ActionResult Team()
        {
            return View();
        }
        [Route("services")]
        public ActionResult Services()
        {
            return View();
        }
    

提交回复
热议问题