Browse Source

Merge pull request #13157 from abpframework/MultiTenancyMiddlewareErrorPageBuilder

Try to delete the tenant's cookie if it does not exist or is inactive.
pull/13165/head
liangshiwei 4 years ago
committed by GitHub
parent
commit
e8fc5ab53a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AspNetCore.MultiTenancy; namespace Volo.Abp.AspNetCore.MultiTenancy;
@ -21,6 +23,15 @@ public class AbpAspNetCoreMultiTenancyOptions
TenantKey = TenantResolverConsts.DefaultTenantKey; TenantKey = TenantResolverConsts.DefaultTenantKey;
MultiTenancyMiddlewareErrorPageBuilder = async (context, exception) => 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.StatusCode = (int)HttpStatusCode.InternalServerError; ;
context.Response.ContentType = "text/html"; 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($"<h3>{message}</h3>{details}<br>\r\n");
await context.Response.WriteAsync("</body></html>\r\n"); await context.Response.WriteAsync("</body></html>\r\n");
// Note the 500 spaces are to work around an IE 'feature' // Note the 500 spaces are to work around an IE 'feature'
await context.Response.WriteAsync(new string(' ', 500)); await context.Response.WriteAsync(new string(' ', 500));
}; };
} }
} }

Loading…
Cancel
Save