From 58b7e40e7c5b8cb75ac6bd31ebe3b768b31611f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 8 Jan 2018 16:32:52 +0300 Subject: [PATCH] Handle to switch to host. --- .../Controllers/MultiTenancyController.cs | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) 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("/"); }