Does registering dynamic routes require an application reload?

I am working on a small CMS for fun, and as part of this I am registering routes from the database when the application starts. User can add route by himself. The problem is that this route is stored in db and therefore does not register until the application is reloaded.

Is it possible to re-register routes without restarting the application?

If not, how can I restart the application on demand?

Greetings

Yang

+6
asp.net-mvc-2 routing
source share
1 answer

No, you can dynamically add and remove routes. RouteTable.Routes is just a RouteCollection that has Add and Remove members (or, if you want, Clear ).

Remember that the web server is multithreaded, so you need to use the RouteCollection blocking RouteCollection . In particular, this means GetWriteLock :

 var routes = RouteTable.Routes; var newDynamicRoute = new Route(...); using(routes.GetWriteLock()) { routes.Remove(dynRoute); dynRoute = newDynamicRoute; routes.Add(dynRoute); } 
+6
source share

All Articles