Browse Source

Merge pull request #13245 from abpframework/MultiTenancyMiddlewareErrorPageBuilder-bool

Add bool return value to `MultiTenancyMiddlewareErrorPageBuilder` decide to continue the pipeline.
pull/13253/head
liangshiwei 4 years ago
committed by GitHub
parent
commit
cbc12060de
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      docs/en/Multi-Tenancy.md
  2. 7
      framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyOptions.cs
  3. 8
      framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/MultiTenancyMiddleware.cs

3
docs/en/Multi-Tenancy.md

@ -44,6 +44,9 @@ Configure<AbpMultiTenancyOptions>(options =>
options.MultiTenancyMiddlewareErrorPageBuilder = async (context, exception) => options.MultiTenancyMiddlewareErrorPageBuilder = async (context, exception) =>
{ {
// Handle the exception. // Handle the exception.
// Return true to stop the pipeline, false to continue.
return true;
}; };
}); });
``` ```

7
framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyOptions.cs

@ -16,7 +16,10 @@ public class AbpAspNetCoreMultiTenancyOptions
/// </summary> /// </summary>
public string TenantKey { get; set; } public string TenantKey { get; set; }
public Func<HttpContext, Exception, Task> MultiTenancyMiddlewareErrorPageBuilder { get; set; } /// <summary>
/// Return true to stop the pipeline, false to continue.
/// </summary>
public Func<HttpContext, Exception, Task<bool>> MultiTenancyMiddlewareErrorPageBuilder { get; set; }
public AbpAspNetCoreMultiTenancyOptions() public AbpAspNetCoreMultiTenancyOptions()
{ {
@ -44,6 +47,8 @@ public class AbpAspNetCoreMultiTenancyOptions
// 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));
return true;
}; };
} }
} }

8
framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/MultiTenancyMiddleware.cs

@ -34,15 +34,17 @@ public class MultiTenancyMiddleware : IMiddleware, ITransientDependency
public async Task InvokeAsync(HttpContext context, RequestDelegate next) public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{ {
TenantConfiguration tenant; TenantConfiguration tenant = null;
try try
{ {
tenant = await _tenantConfigurationProvider.GetAsync(saveResolveResult: true); tenant = await _tenantConfigurationProvider.GetAsync(saveResolveResult: true);
} }
catch (Exception e) catch (Exception e)
{ {
await _options.MultiTenancyMiddlewareErrorPageBuilder(context, e); if (await _options.MultiTenancyMiddlewareErrorPageBuilder(context, e))
return; {
return;
}
} }
if (tenant?.Id != _currentTenant.Id) if (tenant?.Id != _currentTenant.Id)

Loading…
Cancel
Save