Browse Source

Try to delete the tenant's cookie if it does not exist or is inactive.

Resolve #13146
pull/13157/head
maliming 4 years ago
parent
commit
98c8aa69a7
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 15
      framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyOptions.cs

15
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<ITenantResolveResultAccessor>().Result;
if (tenantResolveResult != null &&
tenantResolveResult.AppliedResolvers.Contains(CookieTenantResolveContributor.ContributorName))
{
var options = context.RequestServices.GetRequiredService<IOptions<AbpAspNetCoreMultiTenancyOptions>>().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($"<h3>{message}</h3>{details}<br>\r\n");
await context.Response.WriteAsync("</body></html>\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));
};
}
}

Loading…
Cancel
Save