从数据库中routeconfig动态生成路由

时间:2017-04-12 14:30:34

标签: c# asp.net-mvc wcf asp.net-mvc-routing

我的数据库表中有一些路由存储如下:

/Customer/{Customer}/Address
/Customer/{Customer}/Address/{Address}

以上只是示例,因为我也可以拥有更多路线。

现在我想通过从以下routeconfig中的数据库中获取来在 routeconfig 中动态生成路由:

public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            //I am thinking to generate my routes dyncamically here.
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
            );
        }
    }

所以我的问题是这个解决方案的可行性如何,如果可行,那么我们可以在wcf中做同样的事情吗?

0 个答案:

没有答案