ASP.NET routing - loading routes from a database?

Is it possible to load routes from a database using ASP.NET?

For each r as SomeRouteObject in RouteDataTable routes.MapRoute( _ r.Name, _ r.RouteUri, _ r.RouteValues, _ //?? r.Constraints _ //?? ) Next 

How to save route / restriction values? . I understand that there are several defaults "by default", such as .Controller and .Action , however I also need completely ordinary ones, such as .Id or .Page ...

+3
database routing
source share
1 answer

Think Before You Jump

It is possible, but it is impossible. They provided the route configuration static in Global.asax, because routes are usually static and remain unchanged for a long time. If they do not, you will have problems with SEO anyway. Therefore, I would advise you to first stop and think about whether you really need custom routes.

But probably

But it is possible to use the database in the background to determine your routes. In your case, you can store values ​​as serialized string / value pairs, since RouteValuesDictionary can accept key-value pairs, and also enter values.

If the route definitions remain unchanged in terms of default values ​​/ restrictions, but not URLs, you can provide your own interface and provide classes that implement it. In this case, you can simply store the URLs and class definitions (similar to how they are defined in web.config ) that define values ​​for a specific route. Thus, it is very easy to use complex configurations of objects if you need them ...

+2
source share

All Articles