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
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With