简体   繁体   English

多租户ASP .NET应用程序中的隔离

[英]Isolation in a Multi-tenant ASP .NET Application

I'm building a multi-tenant ASP .NET application. 我正在构建一个多租户ASP .NET应用程序。 Given that each tenant can configure their application dynamically (which may involve dynamic custom assemblies being loaded into memory), I need a means of isolating each tenant. 鉴于每个租户可以动态配置他们的应用程序(可能涉及将动态自定义程序集加载到内存中),我需要一种隔离每个租户的方法。

I'd prefer not to create a new Web Application per tenant for maintenance reasons. 出于维护原因,我不希望为每个租户创建一个新的Web应用程序。

I've was considering using the AppDomainManager to create an AppDomain per application, but it seems this is not intended to be used for ASP .NET applications. 我一直在考虑使用AppDomainManager为每个应用程序创建一个AppDomain,但似乎并不打算用于ASP .NET应用程序。

Does anyone have some suggestions on this subject? 有没有人对这个问题有一些建议?

Thanks. 谢谢。

I guess the question is: If you aren't into creating a Web Application, then what type of isolation is really acceptable to you? 我想问题是:如果你不是在创建一个Web应用程序,那么你真正接受哪种类型的隔离?

If you really want an OS-level guarantee that assemblies won't trod on one another, I would give each their own Web Application. 如果你真的想要一个OS级保证程序集不会相互踩踏,我会给每个人自己的Web应用程序。 This is especially true if you're allowing people to load third-party assemblies, and is super-especially true if those third-party assemblies can find ways to instantiate unmanaged code. 如果您允许人们加载第三方程序集,则尤其如此,如果这些第三方程序集可以找到实例化非托管代码的方法,则尤其如此。

I can see not creating a separate Web Application if it's all your (managed) code, but once you put dynamic custom assemblies into the mix, I think it's the only way to go. 如果它是你的所有(托管)代码,我可以看到没有创建一个单独的Web应用程序,但是一旦你将动态自定义程序集放入混合中,我认为这是唯一的方法。

When you create different web sites, your URL root is definitely gonna change. 当您创建不同的网站时,您的URL根目前肯定会改变。 I was thinking why not different applications inside the main application, and put them in different Application Pools if required? 我在想为什么主应用程序中不同的应用程序,如果需要,将它们放在不同的应用程序池中?

One... That way, the root URL would remain the same. 一个......那样,根URL将保持不变。 Two... Creation a VDir or an instance of an application. 二...创建VDir或应用程序的实例。 Which one needs to be dynamic? 哪一个需要动态? Three... I've no expertise. 三......我没有专业知识。

If I had to share the Pages, [based on applications hosted in different VDir], I would go for creating a new VDir for all my shared pages. 如果我必须共享页面,[基于托管在不同VDir中的应用程序],我会为所有共享页面创建一个新的VDir。 And use some custom code to show application related data. 并使用一些自定义代码来显示应用程序相关数据。

I wrote multi-tenant web application in MVC2. 我在MVC2中编写了多租户Web应用程序。 Adding / Removing an account is as complex as adding / removing a row in a table as I opted for shared database, shared schema approach. 添加/删除帐户与添加/删除表中的行一样复杂,因为我选择了共享数据库,共享模式方法。

This is a very good article about multi-tenant database design from MSDN: Multi-Tenant Data Architecture 这是一篇关于MSDN多租户数据库设计的非常好的文章: 多租户数据架构

All I had to do in MVC is to set up routing properly, so the first part of the path is account name: 我在MVC中所要做的就是正确设置路由,因此路径的第一部分是帐户名:

  • www.yourdomain.com/Account1/... www.yourdomain.com/Account1 / ...
  • www.yourdomain.com/Account2/... www.yourdomain.com/Account2 / ...
  • www.yourdomain.com/Account3/... www.yourdomain.com/Account3 / ...

and I have a custom MvcHandler for looking up account for each request: 我有一个自定义MvcHandler用于查找每个请求的帐户:

public class AccountMvcHandler : MvcHandler
{
    public AccountModel Account { get; set; }

    public AccountMvcHandler(RequestContext requestContext)
        : base(requestContext)
    {
    }

    protected override IAsyncResult BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, object state)
    {
        string accountName = this.RequestContext.RouteData.GetRequiredString("account");
        Account = ServiceFactory.GetService<IAccountService>().GetAccount(accountName);

        // URL doesn't contain valid account name - redirect to login page with Account Name textbox
        if (Account == null)
            httpContext.Response.Redirect(FormsAuthentication.LoginUrl);

        return base.BeginProcessRequest(httpContext, callback, state);
    }
}

As it was said by Andreas Paulsson the key phrase is "custom assemblies". 正如Andreas Paulsson所说,关键词是“自定义组件”。 Why do you need 'custom assemblies' for configuration? 为什么需要“自定义组件”进行配置? Are you using CodeEmit? 你在使用CodeEmit吗? Will users upload them? 用户会上传吗? I would rather think about using Windows Workflow Foundation for any client-specific business logic customisation. 我宁愿考虑使用Windows Workflow Foundation进行任何特定于客户端的业务逻辑定制。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM