mirror of https://github.com/abpframework/abp.git
6 changed files with 47 additions and 17 deletions
@ -1,12 +1,13 @@ |
|||||
using Microsoft.AspNetCore.Http; |
using Microsoft.AspNetCore.Http; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.MultiTenancy |
namespace Volo.Abp.AspNetCore.MultiTenancy |
||||
{ |
{ |
||||
public class CookieTenantResolver : HttpTenantResolverBase |
public class CookieTenantResolver : HttpTenantResolverBase |
||||
{ |
{ |
||||
protected override string GetTenantIdFromHttpContextOrNull(HttpContext httpContext) |
protected override string GetTenantIdFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) |
||||
{ |
{ |
||||
return httpContext.Request.Cookies[Options.TenantIdKey]; |
return httpContext.Request.Cookies[context.GetAspNetCoreMultiTenancyOptions().TenantIdKey]; |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
@ -1,13 +1,32 @@ |
|||||
using Microsoft.AspNetCore.Http; |
using System.Linq; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.ExtensionMethods.Collections.Generic; |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.MultiTenancy |
namespace Volo.Abp.AspNetCore.MultiTenancy |
||||
{ |
{ |
||||
public class HeaderTenantResolver : HttpTenantResolverBase |
public class HeaderTenantResolver : HttpTenantResolverBase |
||||
{ |
{ |
||||
protected override string GetTenantIdFromHttpContextOrNull(HttpContext httpContext) |
protected override string GetTenantIdFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) |
||||
{ |
{ |
||||
//TODO: Get first one if provided multiple values and write a log
|
//TODO: Get first one if provided multiple values and write a log
|
||||
return httpContext.Request.Headers[Options.TenantIdKey]; |
if (httpContext.Request.Headers.IsNullOrEmpty()) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
var tenantIdHeader = httpContext.Request.Headers[context.GetAspNetCoreMultiTenancyOptions().TenantIdKey]; |
||||
|
if (tenantIdHeader == string.Empty || tenantIdHeader.Count < 1) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
if (tenantIdHeader.Count > 1) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
return tenantIdHeader.First(); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
@ -1,17 +1,18 @@ |
|||||
using Microsoft.AspNetCore.Http; |
using Microsoft.AspNetCore.Http; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.MultiTenancy |
namespace Volo.Abp.AspNetCore.MultiTenancy |
||||
{ |
{ |
||||
public class QueryStringTenantResolver : HttpTenantResolverBase |
public class QueryStringTenantResolver : HttpTenantResolverBase |
||||
{ |
{ |
||||
protected override string GetTenantIdFromHttpContextOrNull(HttpContext httpContext) |
protected override string GetTenantIdFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) |
||||
{ |
{ |
||||
if (!httpContext.Request.QueryString.HasValue) |
if (!httpContext.Request.QueryString.HasValue) |
||||
{ |
{ |
||||
return null; |
return null; |
||||
} |
} |
||||
|
|
||||
return httpContext.Request.Query[Options.TenantIdKey]; |
return httpContext.Request.Query[context.GetAspNetCoreMultiTenancyOptions().TenantIdKey]; |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,14 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.MultiTenancy |
||||
|
{ |
||||
|
public static class TenantResolveContextExtensions |
||||
|
{ |
||||
|
public static AspNetCoreMultiTenancyOptions GetAspNetCoreMultiTenancyOptions(this ITenantResolveContext context) |
||||
|
{ |
||||
|
return context.ServiceProvider.GetRequiredService<IOptionsSnapshot<AspNetCoreMultiTenancyOptions>>().Value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue