开发多租户 ASP.NET MVC 应用程序时要记住什么?

发布于 2024-10-16 15:18:24 字数 624 浏览 1 评论 0原文

下午好 - 我今天有一个非常普遍的问题 - 我的任务是创建一个 Web 应用程序来管理客户的一些基本信息。这是一个非常简单的应用程序,但我不知道在开发网站时要记住什么,以支持多个用户在他们自己的域或我们 URL 的子域上?

如何限制用户登录应用程序的彼此部分?

我在 Stack Overflow 上的类似问题中看到过提到数据库范围,有人可以详细说明这样的实现的最佳实践吗?

MVC3 中有支持多租户的新功能吗?我在 MVC2 和我的电子商务网站上遇到了这个问题,我们决定希望它为多个店主提供白标和可定制,并且不知道从哪里开始在现有应用程序中实现这些功能。任何意见都会受到赞赏。

编辑

为了详细说明多租户,我的意思是 - 例如,在商店的上下文中,多个用户在 www.mystore.com 上注册自己的商店,并且每个用户都被赋予一个唯一的子域访问他们自己的商店实例,位于 user1.mystore.com、user2.mystore.com 等。每个商店都有具有订单历史记录的客户,并且这些客户将具有登录名。我需要限制 user1.mystore.com 的客户在没有新帐户的情况下登录 user2.mystore.com,并同样阻止 user2.mystore.com 访问 user1.mystore.com 的客户历史记录。

Good afternoon - I have a pretty general question today - I've been tasked with creating a web application to manage some basic information on customers. It's a very simple application, but what I don't know is what to keep in mind to develop the site around supporting multiple users at their own domains or subdomains of our url?

How would I restrict users from logging in to each others portion of the app?

I've seen mention of database scoping in similar questions on Stack Overflow, could anybody elaborate on best practices for an implementation like this?

Are there any new features in MVC3 to support multi-tenancy? I am facing this issue with MVC2 and my eCommerce site where we decided we wanted it white-labeled and customizable for multiple shop owners, and don't know where to begin in implementing these features in an existing application. Any input is appreciated.

edit

To elaborate on multi-tenancy, what I mean - in the context of a store for example, multiple users sign up for their own store at www.mystore.com and are each given a unique subdomain to access their own instance of the store, at user1.mystore.com, user2.mystore.com etc. Each store would have customers with order histories, and those customers would have logins. I would need to restrict customers of user1.mystore.com from logging in at user2.mystore.com without a new account, and likewise prevent user2.mystore.com from accessing user1.mystore.com's customer history.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笨笨の傻瓜 2024-10-23 15:18:24
無處可尋 2024-10-23 15:18:24

您很可能将花费相当多的时间来重建数据库。

第一步是创建一个表来存放“租户”列表。然后,您需要将此 TenantId 添加到系统中的几乎每个表中,以确保没有人互相干扰。您可以跳过任何本质上是全局的表。一个示例可能是状态代码列表。

然而,从用户到他们拥有的数据等一切都必须有这个 ID。另外,修改所有索引以考虑tenantid。

完成后,您需要修改所有查询以考虑租户 ID。

租户表的一列应该是门户 URL。例如 customername.oursite.com 或其他名称。这样您就可以将多个 url 指向完全相同的代码。当站点需要使用当前的tenantid时,只需根据传入的URL查找它。

如果我这样做,我计划在数据库中的每个表上花费大约1到2小时,以使其成为“多租户” ”。显然,某些表(及其查询)会运行得更快;其他人则需要更长的时间。

顺便说一句,这不包括为每个租户定制 UI(外观/感觉)或任何类似性质的内容。如果您需要这样做,那么您必须在服务器上为每个租户创建一个目录来保存其样式表,或者直接从数据库加载它(数据库在缓存方面有其自身的问题)。

通常,您在项目开始时为此进行设计。改装已经(或几乎)完成的项目是 PITA。

最后,测试、测试、测试、再测试。您必须确保每个查询仅提取它绝对需要的数据。

Most likely you are about to spend a fair amount of time restructuring your database.

The first step is that you are going to create a table to house your "Tenant" list. Then you need to add this TenantId to just about every table in your system to make sure no one steps on each other. You can skip any tables that are global in nature. One example might be a list of Status Codes.

However, everything from users to the data they have etc will have to have this ID. Also, modify all of your indexes to take tenantid into account.

Once you have that, you'll need to modify all of your queries to take the tenantid into account.

One column of the tenants table should be the portal url. Like customername.oursite.com or whatever. This way you could point multiple urls to the exact same code. When the site needs to use the current tenantid just look it up based on the URL the passed in.

If I was doing this, I'd plan to spend about 1 to 2 hours per table in the database to make it "multi-tenant". Obviously some tables (and their queries) will go faster; others will take longer.

Incidentally, this doesn't cover things like customizing the UI (look / feel) per tenant or anything of that nature. If you need to do this then you'll have to either create a directory on the server for each tenant to hold their style sheets or load it directly from the DB (which has it's own issues with regards to caching).

Typically, you design for this at the beginning of the project. Refitting an already (or almost) complete project is a PITA.

Finally, test, test, test and do more testing. You will have to make sure that every single query pulls only the data it absolutely needs to.

自控 2024-10-23 15:18:24

这里有一些关于 Sharp 架构(基于 MVC 3)中多租户支持的讨论:http://www.yellowfeather.co.uk/2011/02/multi-tenancy-on-sharp-architecture-revisited/

不确定这是否真的有帮助如果您使用现有的应用程序,移植将是一项艰巨的工作。

There has been some talk of multi-tenancy support in Sharp Architecture (based on MVC 3) found here: http://www.yellowfeather.co.uk/2011/02/multi-tenancy-on-sharp-architecture-revisited/

Not sure if that really helps you with your existing application, porting over would be a bit of a job.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文