0

How can I loop through all the current routes in the route table and add a new route for all the current pages/actions defined?

I am trying to add a new segment that defines what site a client is on. For example if a user comes in at http:mysite/site/controler/action. The site segment may or may not be in url but I want all current custom routes to be able to route if there is a site segment in the url without having to define a site route manually for every custom route but programatically let mvc routing know it's a valid route and how to route it.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
  • It sounds like you are trying to duplicate the functionality of [`Areas`](https://msdn.microsoft.com/en-us/library/ee671793(v=vs.100).aspx). – NightOwl888 May 16 '16 at 16:44
  • With areas you need to define folders, views, controllers. I am trying to use all my current routes with different tenants and not have to define a tenant with code but data. – user1345234 May 16 '16 at 16:58

1 Answers1

1

You could, but you shouldn't update the route table during runtime. Instead, you should aim to create custom routes that can be changed at runtime.

Two options to do this are:

  1. Create a route-constraint that is driven off of (cached) runtime data. This works well if you have specific segments you would like routing to recognize only when they are defined by your application.
  2. Create a RouteBase override that is driven off of (cached) runtime data.
Community
  • 1
  • 1
NightOwl888
  • 55,572
  • 24
  • 139
  • 212