views:

17

answers:

1

Hi,

I am working on a small CMS for fun and as part of this I register routes from a database at app start. It is possible for a user to add a route themselves. The problem is that this route is stored in the db and so isn't registered until app restart.

Is it possible to re-register routes without an app restart?

If not, how do I restart the app on demand?

Cheers,

Ian

+1  A: 

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

Be aware that the web-server is multithreaded, however, so you'll need to use the RouteCollection's locking protocol. In particular, that means GetWriteLock:

var routes = RouteTable.Routes;
var newDynamicRoute = new Route(...);
using(routes.GetWriteLock()) {
    routes.Remove(dynRoute);
    dynRoute = newDynamicRoute;
    routes.Add(dynRoute);
}
Eamon Nerbonne