committed by
GitHub
15 changed files with 173 additions and 3 deletions
@ -0,0 +1,3 @@ |
|||||
|
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
||||
|
<ConfigureAwait ContinueOnCapturedContext="false" /> |
||||
|
</Weavers> |
||||
@ -0,0 +1,30 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
||||
|
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
||||
|
<xs:element name="Weavers"> |
||||
|
<xs:complexType> |
||||
|
<xs:all> |
||||
|
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
||||
|
<xs:complexType> |
||||
|
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
||||
|
</xs:complexType> |
||||
|
</xs:element> |
||||
|
</xs:all> |
||||
|
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
</xs:complexType> |
||||
|
</xs:element> |
||||
|
</xs:schema> |
||||
@ -0,0 +1,21 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk.Web"> |
||||
|
|
||||
|
<Import Project="..\..\..\..\configureawait.props" /> |
||||
|
<Import Project="..\..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>net9.0</TargetFramework> |
||||
|
<AssemblyName>LINGYUN.Abp.AspNetCore.MultiTenancy</AssemblyName> |
||||
|
<PackageId>LINGYUN.Abp.AspNetCore.MultiTenancy</PackageId> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<OutputType>Library</OutputType> |
||||
|
<Nullable>enable</Nullable> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" /> |
||||
|
</ItemGroup> |
||||
|
</Project> |
||||
@ -0,0 +1,10 @@ |
|||||
|
using Volo.Abp.Modularity; |
||||
|
using VoloAbpAspNetCoreMultiTenancyModule = Volo.Abp.AspNetCore.MultiTenancy.AbpAspNetCoreMultiTenancyModule; |
||||
|
|
||||
|
namespace LINGYUN.Abp.AspNetCore.MultiTenancy; |
||||
|
|
||||
|
[DependsOn(typeof(VoloAbpAspNetCoreMultiTenancyModule))] |
||||
|
public class AbpAspNetCoreMultiTenancyModule : AbpModule |
||||
|
{ |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
namespace LINGYUN.Abp.AspNetCore.MultiTenancy; |
||||
|
|
||||
|
public class AbpAspNetCoreMultiTenancyResolveOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 仅解析域名中的租户, 默认: true
|
||||
|
/// </summary>
|
||||
|
public bool OnlyResolveDomain { get; set; } |
||||
|
public AbpAspNetCoreMultiTenancyResolveOptions() |
||||
|
{ |
||||
|
OnlyResolveDomain = true; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
|
namespace LINGYUN.Abp.AspNetCore.MultiTenancy; |
||||
|
|
||||
|
public static class AbpMultiTenancyOptionsExtensions |
||||
|
{ |
||||
|
public static void AddOnlyDomainTenantResolver(this AbpTenantResolveOptions options, string domainFormat) |
||||
|
{ |
||||
|
options.TenantResolvers.InsertAfter( |
||||
|
r => r is CurrentUserTenantResolveContributor, |
||||
|
new OnlyDomainTenantResolveContributor(domainFormat) |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using System; |
||||
|
using System.Net; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.AspNetCore.MultiTenancy; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.Text.Formatting; |
||||
|
|
||||
|
namespace LINGYUN.Abp.AspNetCore.MultiTenancy; |
||||
|
|
||||
|
public class OnlyDomainTenantResolveContributor : HttpTenantResolveContributorBase |
||||
|
{ |
||||
|
public const string ContributorName = "Domain"; |
||||
|
|
||||
|
public override string Name => ContributorName; |
||||
|
|
||||
|
private static readonly string[] ProtocolPrefixes = { "http://", "https://" }; |
||||
|
|
||||
|
private readonly string _domainFormat; |
||||
|
|
||||
|
public OnlyDomainTenantResolveContributor(string domainFormat) |
||||
|
{ |
||||
|
_domainFormat = domainFormat.RemovePreFix(ProtocolPrefixes); |
||||
|
} |
||||
|
|
||||
|
protected override Task<string?> GetTenantIdOrNameFromHttpContextOrNullAsync(ITenantResolveContext context, HttpContext httpContext) |
||||
|
{ |
||||
|
if (!httpContext.Request.Host.HasValue) |
||||
|
{ |
||||
|
return Task.FromResult<string?>(null); |
||||
|
} |
||||
|
|
||||
|
var options = httpContext.RequestServices.GetRequiredService<IOptions<AbpAspNetCoreMultiTenancyResolveOptions>>(); |
||||
|
if (options.Value.OnlyResolveDomain) |
||||
|
{ |
||||
|
// 仅仅解析域名, 如果请求的是IP地址, 则不使用这个解析贡献者
|
||||
|
if (IPAddress.TryParse(httpContext.Request.Host.Host, out var _)) |
||||
|
{ |
||||
|
return Task.FromResult<string?>(null); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
var hostName = httpContext.Request.Host.Value.RemovePreFix(ProtocolPrefixes); |
||||
|
var extractResult = FormattedStringValueExtracter.Extract(hostName, _domainFormat, ignoreCase: true); |
||||
|
|
||||
|
context.Handled = true; |
||||
|
|
||||
|
return Task.FromResult(extractResult.IsMatch ? extractResult.Matches[0].Value : null); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
{ |
||||
|
"profiles": { |
||||
|
"LINGYUN.Abp.AspNetCore.MultiTenancy": { |
||||
|
"commandName": "Project", |
||||
|
"launchBrowser": true, |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
}, |
||||
|
"applicationUrl": "https://localhost:61811;http://localhost:61812" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue