Changing route pattern in MVC 4 for name / owner / id

I am creating a site that will have multiple vendors using the same site. The URL will look something like this.

www.domainname.com/vendorname

But in MVC, after the forward slash it defaults to the controller. I know you can change the routing tables, but I need it to ignore everything after the first slash and still use the controller. It's just that the url will be www.domainname.com/vendorname/ {controller }/ {id}

How can I configure this to ignore the first parameter and look at the 2nd and 3rd for the controller / id?

Thank!

+3


source to share


1 answer


I think you want to customize ~/App_Start/RouteConfig.cs

:

routes.MapRoute(
  "Default_Vendor",
  "{vendorname}/{controller}/{action}/{id}",
  new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

      



From there you can check RouteData

for vendorname

and use it appropriately (maybe allow a specific database, or use it as a key in a table).

+4


source







All Articles