Dynamic / editable MVC routes stored in the database for the blog engine

I plan to write an MVC blog engine that supports multiple blogs. When creating a blog, the user will be able to choose the path along which his blog will be available.

For instance:

/ blogs / firstBlog /

/ new projects / <big> secondBlog /

/ Foo / bar / thirdblog /

This route information will be stored in the database. Instead of MVC, using only the routes statically declared in Global.asax.cs, I would like to read the routes from the database first. Then, if he does not find anything, cancel the routes declared in Global.asax.cs. Is it possible? If so, what would you suggest doing this?

thank

+3
source share
1 answer

I would declare my default route normal, and then read the database and call the same methods, but instead of passing the string encoded strings, pass the values ​​from the database:

foreach(RouteDetails routeDetails in routesFromDatabase)
{
    routes.MapRoute(
        routeDetails.Name,                                             
        routeDetails.Route,
        routeDetails.Defaults);
}

You need to match the tables correctly and fill in the fields in the imaginary "RouteDetails" object, including the dictionary Defaults(which would probably be the most complex).

Here you can find some examples:

+1
source

Source: https://habr.com/ru/post/1780566/


All Articles