diff --git a/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/MultiTenancyController.cs b/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/MultiTenancyController.cs index 6374b716df..9da448980f 100644 --- a/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/MultiTenancyController.cs +++ b/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/MultiTenancyController.cs @@ -2,6 +2,8 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; +using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.MultiTenancy; using Volo.Abp.Ui; @@ -14,28 +16,37 @@ namespace AbpDesk.Web.Mvc.Controllers public class MultiTenancyController : AbpController { private readonly ITenantStore _tenantStore; + private readonly AspNetCoreMultiTenancyOptions _options; - public MultiTenancyController(ITenantStore tenantStore) + public MultiTenancyController(ITenantStore tenantStore, IOptions options) { _tenantStore = tenantStore; + _options = options.Value; } public async Task SwitchTenant(string tenant = "") { - var tenantInfo = await FindTenantAsync(tenant); - if (tenantInfo == null) + if (tenant.IsNullOrEmpty()) { - throw new UserFriendlyException("Unknown tenant: " + tenant); + HttpContext.Response.Cookies.Delete(_options.TenantKey); } - - HttpContext.Response.Cookies.Append( - "__tenant", - tenantInfo.Id.ToString(), - new CookieOptions + else + { + var tenantInfo = await FindTenantAsync(tenant); + if (tenantInfo == null) { - Expires = DateTimeOffset.Now.AddYears(1) + throw new UserFriendlyException("Unknown tenant: " + tenant); } - ); + + HttpContext.Response.Cookies.Append( + _options.TenantKey, + tenantInfo.Id.ToString(), + new CookieOptions + { + Expires = DateTimeOffset.Now.AddYears(1) + } + ); + } return Redirect("/"); }