Creating routes from database 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 database at this point? For instance:

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 arises from a lack of knowledge about routing, as well as a general lack of knowledge with global.asax. I used global.asaxto use it only for extremely simple tasks; DB feels like I'm moving to another level.

+5
source share
1 answer

Is it safe

What is “safe” and why not?

Routing is built using strings; the code does not matter where these strings come from, whether hardcoded, resource files, web services, a text file, or a database.

, , , , (, , ), .

+1

All Articles