简体   繁体   English

在开发多租户asp.net MVC应用程序时要记住什么?

[英]What to keep in mind when developing a multi-tenant asp.net MVC application?

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. 下午好 - 今天我有一个非常普遍的问题 - 我的任务是创建一个Web应用程序来管理客户的一些基本信息。 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? 我已经看到在Stack Overflow上的类似问题中提到数据库范围,是否有人可以详细说明这样的实现的最佳实践?

Are there any new features in MVC3 to support multi-tenancy? MVC3中是否有任何新功能支持多租户? 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. 我在MVC2和我的电子商务网站面临这个问题,我们决定我们希望它为多个店主提供白色标签和可自定义,并且不知道从哪里开始在现有应用程序中实现这些功能。 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. 详细说明多租户,我的意思是 - 例如,在商店的上下文中,多个用户在www.mystore.com注册他们自己的商店,并且每个用户都有一个唯一的子域来访问他们自己的商店实例,在user1.mystore.com,user2.mystore.com等。每个商店都有订单历史记录的客户,这些客户会有登录。 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. 我需要限制user1.mystore.com的客户在没有新帐户的情况下登录user2.mystore.com,同样阻止user2.mystore.com访问user1.mystore.com的客户历史记录。

I implemented a complete MVC multi-tennant app. 我实现了一个完整的MVC多租户应用程序。 Here are some links I found handy and some sample apps: 以下是我发现的一些链接和一些示例应用程序:

http://msdn.microsoft.com/en-us/library/aa479086.aspx http://msdn.microsoft.com/en-us/library/aa479086.aspx

http://codeofrob.com/archive/2010/02/14/multi-tenancy-in-asp.net-mvc-controller-actions-part-i.aspx http://codeofrob.com/archive/2010/02/14/multi-tenancy-in-asp.net-mvc-controller-actions-part-i.aspx

http://www.developer.com/design/article.php/10925_3801931_2/Introduction-to-Multi-Tenant-Architecture.htm http://www.developer.com/design/article.php/10925_3801931_2/Introduction-to-Multi-Tenant-Architecture.htm

http://msdn.microsoft.com/en-us/library/aa479086.aspx#mlttntda_cc http://msdn.microsoft.com/en-us/library/aa479086.aspx#mlttntda_cc

http://lukesampson.com/post/303245177/subdomains-for-a-single-application-with-asp-net-mvc http://lukesampson.com/post/303245177/subdomains-for-a-single-application-with-asp-net-mvc

http://code.google.com/p/multimvc/ http://code.google.com/p/multimvc/

http://www.paulstovell.com/widgets http://www.paulstovell.com/widgets

http://www.agileatwork.com/bolt-on-multi-tenancy-in-asp-net-mvc-with-unity-and-nhibernate/ http://www.agileatwork.com/bolt-on-multi-tenancy-in-asp-net-mvc-with-unity-and-nhibernate/

http://ayende.com/blog/3530/multi-tenancy-approaches-and-applicability http://ayende.com/blog/3530/multi-tenancy-approaches-and-applicability

http://weblogs.asp.net/zowens/archive/tags/Multi-tenancy/default.aspx http://weblogs.asp.net/zowens/archive/tags/Multi-tenancy/default.aspx

http://cloudsamurai.codeplex.com/ http://cloudsamurai.codeplex.com/

http://cloudninja.codeplex.com/ http://cloudninja.codeplex.com/

http://msdn.microsoft.com/en-us/library/hh534484.aspx http://msdn.microsoft.com/en-us/library/hh534484.aspx

http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx

http://blog.tonywilliams.me.uk/asp-net-mvc-2-routing-subdomains-to-areas http://blog.tonywilliams.me.uk/asp-net-mvc-2-routing-subdomains-to-areas

Even starting from scratch, you are in for a world of hurt. 即使从头开始,你也处于一个受伤的世界。 The MVC framework does very little to help you address the issues. MVC框架在帮助您解决问题方面做得很少。

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. 然后,您需要将此TenantId添加到系统中的每个表中,以确保没有人互相踩踏。 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. 但是,从用户到他们拥有的数据等所有内容都必须具有此ID。 Also, modify all of your indexes to take tenantid into account. 此外,修改所有索引以考虑tenantid。

Once you have that, you'll need to modify all of your queries to take the tenantid into account. 完成后,您需要修改所有查询以考虑tenantid。

One column of the tenants table should be the portal url. 租户表的一列应该是门户URL。 Like customername.oursite.com or whatever. 喜欢customername.oursite.com或其他什么。 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. 当站点需要使用当前的tenantid时,只需根据传入的URL进行查找。

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". 如果我这样做,我打算在数据库中为每个表花费大约1到2个小时来使其成为“多租户”。 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. 顺便提一下,这不包括定制每个租户的UI(外观/感觉)或任何此类性质的内容。 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). 如果您需要这样做,那么您必须在服务器上为每个租户创建一个目录来保存他们的样式表或直接从DB加载它(它有自己的缓存问题)。

Typically, you design for this at the beginning of the project. 通常,您在项目开始时为此进行设计。 Refitting an already (or almost) complete project is a PITA. 改造已经(或几乎)完整的项目是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. 您必须确保每个查询仅提取它绝对需要的数据。

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/ 在Sharp Architecture(基于MVC 3)中有一些关于多租户支持的讨论,请访问: 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. 不确定这对您现有的应用程序是否真的有帮助,移植将是一项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Asp.Net核心多租户 - Asp.Net Core Multi-Tenant 多租户ASP .NET应用程序中的隔离 - Isolation in a Multi-tenant ASP .NET Application Autofac多租户ASP.NET应用程序返回租户而不是标识符 - Autofac Multi-Tenant ASP.NET Application return the tenant instead of the identifier Azure 数据库水平分片是多租户 C# asp.net 应用程序的最佳解决方案 - Azure Database Horizontal Sharding the best solution for Multi-tenant C# asp.net application ASP.NET Identity + Bearer Token + Multi-Tenant - ASP.NET Identity + Bearer Token + Multi-Tenant 确保资源由ASP.NET Core中的多租户系统中的租户拥有 - Making sure resource is owned by tenant in a multi-tenant system in ASP.NET Core 具有租户特定角色的ASP.NET多租户应用程序 - ASP.NET Multi tenant application with tenant specific roles 不支持本机.Net身份验证的多租户OpenID集成到ASP.Net MVC Web应用程序 - Multi tenant OpenID integration to ASP.Net MVC web application without native .Net authentication support 多租户身份验证,ASP.NET样板模块零中的IMustHaveTenant实体 - Multi-tenant authentication, IMustHaveTenant entity in ASP.NET Boilerplate Module Zero 基于多租户Asp.net核心网站中的参数的JWT身份验证 - JWT authentication based on the Parameter in Multi-tenant Asp.net Core web site
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM