windows azure asp.net MVC2 中的多租户

发布于 2024-09-18 04:57:56 字数 160 浏览 10 评论 0原文

任何人都知道我如何开始在 MVC2 中开发多租户站点(以在 Windows Azure 上运行的方式)?

我搜索了很多关于这个问题的信息,我总是找到理论解释,每个人都说这很容易完成,但我没有找到任何示例......

有人可以解释我从哪里开始吗?

谢谢, 若昂

Anyone knows how can i start to develop a multitenant site in MVC2, in a way it run on Windows Azure?

I search a lot about this question, and i allways find theoric explanations, everybody says it can be easily done, but i dont find any sample...

Can someone explain me where to start?

Thanks,
João

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

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

发布评论

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

评论(4

爱的那么颓废 2024-09-25 04:58:08

首先,所有答案都非常非常有帮助。它正在改变您想要设置多租户的决定。我的意思是最重要的是识别应用程序中的所有租户,因此有很多解决方案。例如,您可以保留您的通过子域或 URL 冲浪来租户。也许您还可以存储您的数据多租户数据库。

史蒂夫·摩根(Steve Morgan)写了一些非常非常有帮助的帖子。

我只帮助您设置启动多租户。以下是博客:

  1. 识别多租户 Azure 应用程序中的租户 - 第 1 部分
  2. 识别多租户 Azure 应用程序中的租户 - 第 2 部分
  3. 识别多租户 Azure 应用程序中的租户 - 第 3 部分

以下是 Windows Azure 的多租户数据策略:

  1. Windows Azure 的多租户数据策略 –第 1 部分
  2. 多租户Windows Azure 数据策略 – 第 2 部分

First , all answers are very very helpful.It's changing your decision what you want setting up your multitenancy.I mean the most important thing is Identifying all tenant in your app so there is a lot of way for solution.For example you can hold your tenant via subdomains or URL surfing.And also maybe you can store your data multitenat database.

There are very very helpul posts are written by Steve Morgan.

I only help you for set startup multi- tenancy.Here are the blogs :

  1. Identifying the Tenant in Multi-Tenant Azure Applications - Part 1
  2. Identifying the Tenant in Multi-Tenant Azure Applications - Part 2
  3. Identifying the Tenant in Multi-Tenant Azure Applications - Part 3

And here are the Multi-Tenant Data Strategies for Windows Azure :

  1. Multi-Tenant Data Strategies for Windows Azure – Part 1
  2. Multi-Tenant Data Strategies for Windows Azure – Part 2
故笙诉离歌 2024-09-25 04:58:06

在本指南中,我们介绍了这方面的各个方面,其中包括使用 MVC 2 的完整示例。
链接文本

In this guide we cover aspects of this and it includes a full sample using MVC 2.
link text

杀手六號 2024-09-25 04:58:04

它非常复杂,不能掉以轻心。不过,请看一下 Microsoft Orchard 项目的源代码。如果您需要的话,它具有完整的多租户功能:http://orchard.codeplex.com/

他们的构建也可以在 Azure 中运行。

Its hugely complex and not something to be taken on lightly. However take a look at the source code for Microsoft's Orchard project. This has full multi-tenancy capabilities if thats what you need: http://orchard.codeplex.com/

And they have a build that works in Azure too.

永言不败 2024-09-25 04:58:02

这取决于您计划如何实施多租户(例如,使用通用 URL、子域、自定义域或任意组合的授权)。但您应该能够使用 Azure 和 MVC2 执行几乎任何方法。如果您计划为每个租户使用自定义域而不是子域,则需要使用 CNAME 条目(而不是 A 记录)将每个自定义域指向 Azure,但这通常不是问题。

MVC 提供了许多扩展点,您可以在其中实现各种风格的多租户。主要目标是通过登录名或 URL 来唯一标识用户。

我们有一个在 Azure 中运行的 MVC2 应用程序,它解析请求 url 以区分租户。有很多方法可以做到这一点。我们采用扩展 Controller 类的方法来为我们的应用程序提供唯一的租户信息,以便我们可以根据需要使用它来进行适当的存储库调用以显示正确的视图等。

以下是示例多租户控制器可能如下所示:

public class MultiTenantController : Controller {
    public string TenantCode { get; set; }

    protected override void OnActionExecuting(ActionExecutingContext filterContext) {
        TenantCode = GetTenantCode(filterContext.HttpContext.Request);
    }

    private string GetTenantCode(System.Web.HttpRequestBase request) {
        string host = new RequestParser(request.Url.AbsoluteUri).Host;
        return _tenantService.GetTenantCodeByHostAddress(host);
    }
}

注释:

  1. RequestParser 函数
    上面只是任何实现
    知道如何解析 a 中的 url
    安全的方式。
  2. _tenantService
    可以访问某种持久的
    存储(在我们的例子中为 Azure 表)到
    从主机获取 TenantCode
    url 中的地址。

您的所有控制器都将从上面的类继承。然后,为了区分租户,您只需在控制器中引用 TenantCode 即可,如下所示:

public class HomeController : MultiTenantController {
    ...

    public ViewResult Index() {
        var vm = _homeService.GetHomePageViewModelForTenant(TenantCode);
        return View(vm);
    }
}

使用上述实现,您可以向如下 URL 提供不同的站点或数据:
http://subtenant1.yourdomain.com
http://subtenant2.yourdomain.com
http://www.customtenantdomain.com

您的后端存储(例如表存储)只需要交叉引用主机名与租户的关系如下表所示。在上面的代码中,GetTenantCode 将访问数据。

HostName                TenantCode
---------------------- --------------  
subtenant1              Tenant1ID  
subtenant2              Tenant2ID  
www.customtenantdomain  Tenant3ID  

为了使 www.customtenantdomain.com 正常工作,租户需要在指向 Azure Web 角色地址的 customtenantdomain.com 的 DNS 记录中添加 www 的 CNAME 条目。

It depends on how you plan on implementing multitenancy (eg. using authorization with common urls, subdomains, custom domains, or any combination). But you should be able to do just about any approach with Azure and MVC2. If you plan on using a custom domain for each tenant, versus a subdomain, you will need to be happy with using CNAME entries (not A records) to point each custom domain to Azure but that usually is not a problem.

MVC offers many extension points where you can implement multitenancy in its various flavors. The main goal is to uniquely identify the user by either a login or the url.

We have an MVC2 application running in Azure that parses the request url to differentiate the tenant. There are many ways to do this. We took the approach of extending the Controller class to provide our app with the unique tenant information so we could use it as needed to make appropriate repository calls to display the proper views etc.

Here is a sample of what a MultiTenant Controller might look like:

public class MultiTenantController : Controller {
    public string TenantCode { get; set; }

    protected override void OnActionExecuting(ActionExecutingContext filterContext) {
        TenantCode = GetTenantCode(filterContext.HttpContext.Request);
    }

    private string GetTenantCode(System.Web.HttpRequestBase request) {
        string host = new RequestParser(request.Url.AbsoluteUri).Host;
        return _tenantService.GetTenantCodeByHostAddress(host);
    }
}

NOTES:

  1. The RequestParser function
    above is just any implementation
    that knows how to parse urls in a
    safe manner.
  2. _tenantService
    can access some kind of persistent
    store (Azure Tables in our case) to
    get the TenantCode from the host
    address in the url.

All of your controllers would inherit from the above class. Then, to differentiate between tenants you just refer to the TenantCode within your controller like so:

public class HomeController : MultiTenantController {
    ...

    public ViewResult Index() {
        var vm = _homeService.GetHomePageViewModelForTenant(TenantCode);
        return View(vm);
    }
}

Using the above implementation you could serve different sites or data to urls like the following:
http://subtenant1.yourdomain.com
http://subtenant2.yourdomain.com
http://www.customtenantdomain.com

Your backend store (eg. Table Storage) just needs to cross reference host names with the tenant like the table below. In the code above GetTenantCode would access the data.

HostName                TenantCode
---------------------- --------------  
subtenant1              Tenant1ID  
subtenant2              Tenant2ID  
www.customtenantdomain  Tenant3ID  

For www.customtenantdomain.com to work, the tenant needs a CNAME entry for www in their DNS records for customtenantdomain.com that points to your Azure Web Role's address.

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