diff --git a/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyOptions.cs b/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyOptions.cs index 4f89ef7b97..d3b66952ef 100644 --- a/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyOptions.cs +++ b/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyOptions.cs @@ -3,6 +3,8 @@ using System.Globalization; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Volo.Abp.MultiTenancy; namespace Volo.Abp.AspNetCore.MultiTenancy; @@ -21,6 +23,15 @@ 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().Result; + if (tenantResolveResult != null && + tenantResolveResult.AppliedResolvers.Contains(CookieTenantResolveContributor.ContributorName)) + { + var options = context.RequestServices.GetRequiredService>().Value; + AbpMultiTenancyCookieHelper.SetTenantCookie(context, null, options.TenantKey); + } + context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; ; context.Response.ContentType = "text/html"; @@ -31,8 +42,8 @@ public class AbpAspNetCoreMultiTenancyOptions await context.Response.WriteAsync($"

{message}

{details}
\r\n"); await context.Response.WriteAsync("\r\n"); - // Note the 500 spaces are to work around an IE 'feature' - await context.Response.WriteAsync(new string(' ', 500)); + // Note the 500 spaces are to work around an IE 'feature' + await context.Response.WriteAsync(new string(' ', 500)); }; } }