Merge pull request #16123 from abpframework/auto-merge/rel-7-1/1835

Merge branch dev with rel-7.1
pull/16131/head
maliming 3 years ago committed by GitHub
commit 98f069fdd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,7 @@ using System.Globalization;
using System.Net;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
@ -27,13 +28,30 @@ public class AbpAspNetCoreMultiTenancyOptions
TenantKey = TenantResolverConsts.DefaultTenantKey;
MultiTenancyMiddlewareErrorPageBuilder = async (context, exception) =>
{
// Try to delete the tenant's cookie if it does not exist or is inactive.
var tenantResolveResult = context.RequestServices.GetRequiredService<ITenantResolveResultAccessor>().Result;
if (tenantResolveResult != null &&
tenantResolveResult.AppliedResolvers.Contains(CookieTenantResolveContributor.ContributorName))
if (tenantResolveResult != null)
{
if (tenantResolveResult.AppliedResolvers.Count == 1 && tenantResolveResult.AppliedResolvers.Contains(CurrentUserTenantResolveContributor.ContributorName))
{
var authenticationType = context.User.Identity?.AuthenticationType;
if (authenticationType != null)
{
var scheme = await context.RequestServices.GetRequiredService<IAuthenticationHandlerProvider>().GetHandlerAsync(context, authenticationType);
if (scheme is IAuthenticationSignOutHandler signOutHandler)
{
// Try to delete the authentication's cookie if it does not exist or is inactive.
await signOutHandler.SignOutAsync(null);
}
}
}
var options = context.RequestServices.GetRequiredService<IOptions<AbpAspNetCoreMultiTenancyOptions>>().Value;
AbpMultiTenancyCookieHelper.SetTenantCookie(context, null, options.TenantKey);
if (tenantResolveResult.AppliedResolvers.Contains(CookieTenantResolveContributor.ContributorName) ||
context.Request.Cookies.ContainsKey(options.TenantKey))
{
// Try to delete the tenant's cookie if it does not exist or is inactive.
AbpMultiTenancyCookieHelper.SetTenantCookie(context, null, options.TenantKey);
}
}
context.Response.Headers.Add("Abp-Tenant-Resolve-Error", exception.Message);

Loading…
Cancel
Save