动态/可编辑的 MVC 路由存储在博客引擎的数据库中
我打算写一个MVC博客引擎,支持多个博客。创建博客时,用户将能够选择访问其博客的路径。
例如:
/blogs/firstBlog/
/newprojects/secondBlog/
/foo/bar/thirdblog/
该路线信息将存储在数据库中。我希望 MVC 首先从数据库中读取路由,而不是仅使用 Global.asax.cs 中静态声明的路由。然后,如果找不到任何内容,则回退到 Global.asax.cs 中声明的路由。这可能吗?如果是的话,您会建议什么来实现这一目标?
谢谢
I'm planning to write an MVC blog engine, supporting multiple blogs. When creating a blog the user will be able to choose the path where his blog will be accessed.
For example:
/blogs/firstBlog/
/newprojects/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'd like it to read the routes from the database first. Then if it doesn't find anything, fallback on the routes declared in Global.asax.cs. Is this possible? If yes what would you suggest to accomplish that?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会像平常一样声明您的默认路由,然后读取数据库并调用相同的方法,但不是传递硬编码字符串,而是传递数据库中的值:
您需要正确映射表并填充想象的对象“RouteDetails”中的字段,包括
Defaults
字典(这可能是最复杂的)。您可以在这里找到几个示例:
数据库
I'd declare your default route as normal, and then read the database and call the same methods, but rather than passing in hard coded strings, pass in the values from the database:
You'll need to map the tables properly and populate the fields in the imagined object 'RouteDetails', including the
Defaults
dictionary (which would probably be the most complicated).You can find a couple of examples here:
database