In my Global.asax
file on Application_Start
I create a certain number of routes in RouteTable.Routes
by looping through a list of web pages collected from a database. This works fine, all routes are created and function as required. But in my web application the user can modify the database and therefore the collection of web pages. This means that during the life cycle of the application some of the routes become invalid, and new routes should be added.
What I wish to do is: The moment the user changes something to the web pages collection, I would like to clear the RouteTable and reload it by looping through the (modified) web pages collection again.
Unfortunately the Application_Start
in Global.asax
is ran only once, namely at the beginning of the application. I tried moving it to Session_Start
which results in undesired behaviour due to the RoutesTable
being static.
How do I give my user the ability to change the web page collection on-the-fly whilst having the static RouteTable
remain 'in-sync' with it?
Edit
At the moment I do something like this (pseudo-code):
public class WebPageInfo // represents a record in the database
{
public string Title; // My nice page
public string Url; // NicePage
public string PhysicalFile; // ~/Page.aspx
}
In Global.asax:
protected virtual void Application_Start(object sender, EventArgs e)
{
foreach (WebPageInfo webPageInfo in webPageInfos)
{
RouteTable.RegisterRoute(webPageInfo.Title, webPageInfo.Url, webPageInfo.PhysicalFile);
}
}
The problem is that during the life cycle of the application users can add/modify/delete records in the webPageInfos
, how do I update the RouteTable with these changes?