ASP.NET 多租户路由配置
这不是如何实现多租户的问题。我正在寻找的是能够在需要时选择性地覆盖默认应用程序路由的能力。
一个简单的情况是,我有一个生成博客网址的路由,如下所示:
http://[domain]/blog/post-slug
我的配置是 blog/{slug}
但是,一些租户确实希望将他们的博客称为“新闻” ”。虽然我可以在视图中更改所有引用博客,但我无法在 URL 中执行此操作。
我想要一种简单的方法来覆盖这些路由配置而不更改“核心”代码库。
我的一个想法是使用命名路由,然后在应用程序启动时使用它来交换路由配置。我应该补充一点,多个租户不会使用相同的应用程序实例,而只会使用相同的代码库。
谢谢, 本
This is not a question of how to implement multi-tenancy. What I am looking for is the ability to optionally override the default application routes when required.
A simple case is that I have a route that generates a blog url like so:
http://[domain]/blog/post-slug
My configuration is blog/{slug}
However, some tenants do wish to call their blog "news". Although I can change all references blog in their views, I can't do it in the URL.
I would like a simple way of overriding these route configurations without changing the "core" codebase.
One thought I had would be to use named routes and then use this to swap out route configurations when the app starts. I should add that multiple tenants will not be using the same application instance, just the same codebase.
Thanks,
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您始终可以使用正则表达式添加路由。还有一个很棒的工具可以帮助您确定要添加哪些路线才能获得您想要的东西。
http://haacked.com/archive/2008/03/13 /url-routing-debugger.aspx
You can always add a route using a regular expression. There is also a great tool on figuring out what routes to add to get what you want.
http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
如果您有一个过滤器可以检测正在访问该操作的用户类型,该怎么办?如果有人想要新闻这个词,你可以将他们重定向到一个名为新闻的控制器 - 它继承了博客的所有功能。
我不能说我有 100% 的信心,但我认为这可能会起作用。
What about if you have a filter that detects which type of user is accessing the action. If it is one who wants the word news, you can redirect them to a controller called news - which inherits all the functionality from blog.
I can't say I'm 100% confident, but I think it might work.