且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在asp.net-core中实现多租户功能

更新时间:2023-02-17 07:44:35

我相信您正在寻找的方法与下面网址中的文章类似.

The approach I believe you are looking for is similar to the article at the url below.

https://dotnetthoughts.net/building-多租户web应用与aspnet核心/

在其中,作者将请求的URL拆分为由地址中的点分隔的字符串数组.然后将变量子域"设置为该数组的第一个元素.在您的问题中,看起来您可能想使用数组中的第二个元素,但是您明白了.

In it, the author splits the requesting URL into an array of strings delimited by the dot in the address. The variable 'subdomain' is then set to the first element of that array. In your question, it looks like you may want to use the second element in the array, but you get the idea.

var fullAddress = actionExecutingContext.HttpContext?.Request?
     .Headers?["Host"].ToString()?.Split('.');

var subdomain = fullAddress[0];
//do something, get something, return something

如何使用这些数据取决于您.本文的作者创建了一个filter属性,但是有很多可能性,例如将承租人名称作为参数传递给服务函数.

How you use this data is up to you. The author of the article created a filter attribute, but there are many possibilities such as passing the tenant name as a parameter to a service function.