Current ASAX code (simplified):
void Application_Start(object sender, EventArgs e)
{
// Enable routing
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
routes.Add("ContactUsRoute",
new Route("contact-us",
new PageRouteHandler("~/contactus.aspx")));
}
Question
Is it safe to pull routes from the DB at this point? For example:
void RegisterRoutes(RouteCollection routes)
{
routes.Add("ContactUsRoute",
new Route("contact-us",
new PageRouteHandler("~/contactus.aspx")));
// BusinessLogic.GetPageRoutes() returns a List<Route>
var dbRoutes = BusinessLogic.GetPageRoutes();
foreach (Route route in dbRoutes)
{
routes.Add(route);
}
}
Additional Information
This question is born out of a lack of knowledge concerning routing as well as a general unfamiliarity with global.asax
. In the past, I've only used global.asax
for extremely simple tasks; DB feels like I'm taking it to another level.
Is it safe
What is "safe" and why wouldn't this be?
Routing is built using strings, the code doesn't matter where those strings come from, whether it's hardcoded, resource files, web services, a text file or a database.
As long as you make sure you've got some default routes up for showing error pages when the database is unavailable, I can't see (apart from perhaps the performance penalty on the first hit) why you wouldn't do it this way.
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