ASP.NET MVC URL pointing to the same action

How to map multiple urls with the same action in asp.net mvc

I have:

string url1 = "Help/Me";
string url2 = "Help/Me/Now";
string url3 = "Help/Polemus";
string url1 = "Help/Polemus/Tomorow";

In my global.asax.cs file, I want to map all of these URLs to the following action:

public class PageController : Controller
{
    [HttpGet]
    public ActionResult Index()
    {
        return View();
    }
}
+5
source share
4 answers

Add the following table to the routing table:

routes.MapRoute("RouteName", "Help/{Thing}/{OtherThing}", new { controller = "Page" });

EDIT

foreach(string url in urls)
    routes.MapRoute("RouteName-" + url, url, new { controller = "Page", action = "Index" });
+6
source

Now in MVC 5 this can be achieved using the route attribute.

[Route("Help"/"Me")]
[Route("Help/Me/Now")]
[Route("Help/Polemus")]
[Route("Help/Polemus/Tomorow")]
public ActionResult Index()
 {
    return View();
 }
+17
source

" " . RouteConfig.cs, .

"" :

routes.MapRoute(
    "UniqueHomePage",
    "Default",
    new { controller = "Redirector", action = "RedirectToRoot" }
);

routes.MapRoute(
    "UniqueHomePage2",
    "Home",
    new { controller = "Redirector", action = "RedirectToRoot" }
);

:

routes.MapRoute(
    "UniqueHomePageGeneric",
     "{url}",
      new { controller = "Redirector", action = "RedirectToRoot" },
      new { url = "Home|Default" }
);

SEO-savy -interested: URL- - . . , . NON-, , , : P.

+4

, . , URL- /. .

URL-, , , . /Help/Me /Help/ {Page}, . /help/ {page} 1, /help/me, .

On the other hand, if this is a public site and SEO is important, be careful if you have multiple URLs returning the same data, it will be marked as duplicate. If so, use the Canonical tag , this gives the entire page rank of all the URLs that go to this single page in the name you name, and removes the problem of duplicate content.

+3
source

All Articles