How To remove or Hide controller and action from URL in MVC4
Hi, I have a question, Let's suppose a website in MVC like fashionmitra.com. if my need will be to hide controller and action from http://www.fashionmitra.com/shop/product/WOMEN as shop is controller,and product is action from url. Then what will be the best option.

Mageshwaran RPosted Nov 18, 2019, 11:58 PM
Pritesh BhoiPosted Sep 6, 2019, 11:54 PM
Munesh SharmaPosted May 2, 2016, 2:28 PM
Make the other route1, route2 are after default routemap
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "route1",
url: "{controller}/{action}/{id}",
defaults: new { controller = "controller1", action = "action3", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "route2",
url: "{controller}/{action}/{id}",
defaults: new { controller = "controller2", action = "action4", id = UrlParameter.Optional }
);
}
Annad KumarPosted Apr 29, 2016, 3:03 AM
DhanasekarPosted Apr 25, 2016, 4:23 AM
Global.asax.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Content", "{page}", new { controller = "ContentBuilder", action = "DisplayPage" }, new { page = @".*\.html" });
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" });
}
ContentBuilderController.cs
public class ContentBuilderController : Controller
{
public ActionResult DisplayPage(string page)
{
// TODO: Validate
return Content(String.Concat("
", page, "
"), System.Net.Mime.MediaTypeNames.Text.Html);}
}
The URL remains as entered, e.g. "http://localhost/test/aaa.html".