|
|
|
@ -4,7 +4,9 @@ using System.Net; |
|
|
|
using System.Text.Encodings.Web; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Authentication; |
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Http.Extensions; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Volo.Abp.MultiTenancy; |
|
|
|
@ -28,6 +30,7 @@ public class AbpAspNetCoreMultiTenancyOptions |
|
|
|
TenantKey = TenantResolverConsts.DefaultTenantKey; |
|
|
|
MultiTenancyMiddlewareErrorPageBuilder = async (context, exception) => |
|
|
|
{ |
|
|
|
var isCookieAuthentication = false; |
|
|
|
var tenantResolveResult = context.RequestServices.GetRequiredService<ITenantResolveResultAccessor>().Result; |
|
|
|
if (tenantResolveResult != null) |
|
|
|
{ |
|
|
|
@ -37,10 +40,11 @@ public class AbpAspNetCoreMultiTenancyOptions |
|
|
|
if (authenticationType != null) |
|
|
|
{ |
|
|
|
var scheme = await context.RequestServices.GetRequiredService<IAuthenticationHandlerProvider>().GetHandlerAsync(context, authenticationType); |
|
|
|
if (scheme is IAuthenticationSignOutHandler signOutHandler) |
|
|
|
if (scheme is CookieAuthenticationHandler cookieAuthenticationHandler) |
|
|
|
{ |
|
|
|
// Try to delete the authentication's cookie if it does not exist or is inactive.
|
|
|
|
await signOutHandler.SignOutAsync(null); |
|
|
|
await cookieAuthenticationHandler.SignOutAsync(null); |
|
|
|
isCookieAuthentication = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -54,19 +58,27 @@ public class AbpAspNetCoreMultiTenancyOptions |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
context.Response.Headers.Add("Abp-Tenant-Resolve-Error", exception.Message); |
|
|
|
context.Response.StatusCode = (int)HttpStatusCode.NotFound; |
|
|
|
context.Response.ContentType = "text/html"; |
|
|
|
if (isCookieAuthentication && context.Request.Method.Equals("Get", StringComparison.OrdinalIgnoreCase) && !context.Request.IsAjax()) |
|
|
|
{ |
|
|
|
context.Response.Headers.Add("Abp-Tenant-Resolve-Error", exception.Message); |
|
|
|
context.Response.Redirect(context.Request.GetEncodedUrl()); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
context.Response.Headers.Add("Abp-Tenant-Resolve-Error", exception.Message); |
|
|
|
context.Response.StatusCode = (int)HttpStatusCode.NotFound; |
|
|
|
context.Response.ContentType = "text/html"; |
|
|
|
|
|
|
|
var message = exception.Message; |
|
|
|
var details = exception is BusinessException businessException ? businessException.Details : string.Empty; |
|
|
|
var message = exception.Message; |
|
|
|
var details = exception is BusinessException businessException ? businessException.Details : string.Empty; |
|
|
|
|
|
|
|
await context.Response.WriteAsync($"<html lang=\"{HtmlEncoder.Default.Encode(CultureInfo.CurrentCulture.Name)}\"><body>\r\n"); |
|
|
|
await context.Response.WriteAsync($"<h3>{HtmlEncoder.Default.Encode(message)}</h3>{HtmlEncoder.Default.Encode(details)}<br>\r\n"); |
|
|
|
await context.Response.WriteAsync("</body></html>\r\n"); |
|
|
|
await context.Response.WriteAsync($"<html lang=\"{HtmlEncoder.Default.Encode(CultureInfo.CurrentCulture.Name)}\"><body>\r\n"); |
|
|
|
await context.Response.WriteAsync($"<h3>{HtmlEncoder.Default.Encode(message)}</h3>{HtmlEncoder.Default.Encode(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)); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
}; |
|
|
|
|