动态加载模块的租户特定路由
我正在使用 ASP.NET MVC 开发应用程序框架。本质上,最终目标是能够登录管理界面,创建具有自定义设置的新租户,启用他们想要的模块(博客、购物篮等)......工作完成 - 客户对新网站感到满意。我没有使用单独的应用程序,因为会有很多共享代码,这样维护起来会更容易,而且还因为在高峰时间在线引入一个新的、相同的节点非常容易。
根据为租户加载的模块,每个租户适用不同的路由。在我看来,有三个选项:
让所有租户共享相同的路线集合 - 但是,如果有很多模块,它将搜索很多不需要的路线,并且某些模块很可能有冲突的路线。
将每个租户的必要路由添加到全局路由集合中,并扩展路由类以查看域 - 但随着添加更多租户,这可能很快就会产生数百条路由。
首先弄清楚哪个租户正在被访问,然后只搜索他们自己的私人路线集合 - 这将是理想的选择,但我已经搜索了几个小时并且完全不知道如何做到这一点!
那么有人可以为我指出第三个选项的正确方向,或者解释为什么前两个选项中的任何一个都没有那么糟糕吗?
I am using ASP.NET MVC to develop an application framework. Essentially, the end goal is to be able to log into an admin interface, create a new tenant with custom settings, enable the modules they want (blog, shopping basket, etc)... job done - satisfied customer with new website. I'm not using separate applications because there will be a lot of shared code and it would be easier to maintain this way, and also because it would be pretty easy to bring a new, identical node online at peak times.
Depending on what modules are loaded for the tenant, different routes are applicable for each tenant. As I see it, there are three options:
Have all tenants share the same route collection - however if there are a lot of modules it'll be searching through a lot of routes it doesn't need to, and some modules may well have conflicting routes.
Add the necessary routes for each tenant to the global route collection and extend the route class to look at the domain as well - but this could quickly end up with hundreds of routes as more tenants are added.
Work out what tenant is being accessed first and then only search their own private route collection - this would be ideal, but I've searched for hours and have absolutely no idea how to do it!
So can anyone point me in the correct direction for the third option or explain why either of the first two aren't really that bad?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的应用程序中如何区分每个网站?如果我们假设每个租户都由唯一的域名或子域名标识,那么您可以使用一条路由和一些
RouteConstraints
来完成路由。创建两个约束,一个用于控制器,另一个用于操作。假设您的数据库中有列出特定租户的可用控制器/操作的表,您的约束如下:然后,在 Global.asax.cs 中,按如下方式定义您的路由:
当请求传入时,约束将检查控制器和操作对于域是否有效,以便只有对该租户有效的控制器和操作才会通过 RouteConstraints。
How will each website be distinguished in your app? If we assume each tenant will be identified by a unique domain name or subdomain name, then you can accomplish your routing with one route and some
RouteConstraints
. Create two constraints, one for controllers, the other for actions. Assuming that you will have tables in your database which list the available controllers/actions for a specific tenant, your constraints would be as follows:Then, in Global.asax.cs, define your route as follows:
When a request comes in, the constraints will examine whether the controller and action are valid for the domain, so that only valid controllers and actions for that tenant will pass the RouteConstraints.