How can we configure multiple URls for same Action name in ASP.Net MVC?

Solution

We can define multiple URLs in MVC by specifying multiple routes in Route.config file.

routes.MapRoute(
                name: "Route1",
                url: "{controllerName}/Aboutus",
                defaults: new { controller = "Home", action = "About", id = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "Route2",
                url: "{controllerName}/About-us",
                defaults: new { controller = "Home", action = "About", id = UrlParameter.Optional }
            );

Now following URLs will be mapped to this action name

  • http://localhost:64922/Home/Aboutus
  • http://localhost:64922/Home/About-us

Share this thread

Comments

Comments
comments powered by Disqus

Navigation

Social Media