I am adding a route dynamically to the RouteTable, but the update is not propagating to the other processes:
using (RouteTable.Routes.GetWriteLock())
{
RouteTable.Routes.MapPageRoute(
String.Format("_{0}", routeName),
routeName,
"~/Template.aspx",
true,
new RouteValueDictionary {{"page", routeName}});
}
This correctly creates the correct route, as I can access it sometimes, but if get switched to a new process or if I try a bit later on, I can't access the page. If I then restart the app pool, it works fine. Also if I wait long enough, a few hours, when the processes have been recycled, the routes work.
I am thinking that this is a result of a route being created on the one process, and only on future process recycles.
Hay ideas on how to push the route updates out?
I think the problem is with the implementation of Routes
. As we can see here - RouteTable.Routes
is static. So the issue here is not why the routes are not propogating to all processes, but more of a static variable in a web garden issue.
Trying to think of a workaround, what I can come up with is a solution similar to the sharing cache between web garden processes / web servers in a cluster. You need to take the list of dynamic routes OutProc
and in to a DB or static file. Your code then needs to track these files for changes and add new routes when they are added to the external resource.