public 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"; var message = exception.Message; var details = exception is BusinessException businessException ? businessException.Details : string.Empty; await context.Response.WriteAsync($"<html lang=\"{CultureInfo.CurrentCulture.Name}\"><body>\r\n"); 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)); return(true); }; }
public async Task InvokeAsync(HttpContext context, RequestDelegate next) { TenantConfiguration tenant = null; try { tenant = await _tenantConfigurationProvider.GetAsync(saveResolveResult : true); } catch (Exception e) { if (await _options.MultiTenancyMiddlewareErrorPageBuilder(context, e)) { return; } } if (tenant?.Id != _currentTenant.Id) { using (_currentTenant.Change(tenant?.Id, tenant?.Name)) { if (_tenantResolveResultAccessor.Result != null && _tenantResolveResultAccessor.Result.AppliedResolvers.Contains(QueryStringTenantResolveContributor.ContributorName)) { AbpMultiTenancyCookieHelper.SetTenantCookie(context, _currentTenant.Id, _options.TenantKey); } var requestCulture = await TryGetRequestCultureAsync(context); if (requestCulture != null) { CultureInfo.CurrentCulture = requestCulture.Culture; CultureInfo.CurrentUICulture = requestCulture.UICulture; AbpRequestCultureCookieHelper.SetCultureCookie( context, requestCulture ); context.Items[AbpRequestLocalizationMiddleware.HttpContextItemName] = true; } await next(context); } } else { await next(context); } }
public virtual async Task OnPostAsync() { Guid?tenantId = null; if (!Input.Name.IsNullOrEmpty()) { var tenant = await TenantStore.FindAsync(Input.Name); if (tenant == null) { throw new UserFriendlyException(L["GivenTenantIsNotExist", Input.Name]); } if (!tenant.IsActive) { throw new UserFriendlyException(L["GivenTenantIsNotAvailable", Input.Name]); } tenantId = tenant.Id; } AbpMultiTenancyCookieHelper.SetTenantCookie(HttpContext, tenantId, Options.TenantKey); }