|  |  |  | @ -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); | 
			
		
	
	
		
			
				
					|  |  |  | 
 |