Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating routes from DB records

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.

like image 343
James Hill Avatar asked Nov 12 '22 09:11

James Hill


1 Answers

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.

like image 151
CodeCaster Avatar answered Nov 15 '22 13:11

CodeCaster