5

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.

4

1 回答 1

1

是否安全

什么是“安全的”,为什么不这样呢?

路由是使用字符串构建的,代码与这些字符串的来源无关,无论是硬编码、资源文件、Web 服务、文本文件还是数据库。

只要您确保在数据库不可用时有一些默认路由来显示错误页面,我看不出(除了第一次命中时的性能损失)为什么不这样做.

于 2013-03-12T16:14:01.710 回答