diff --git a/YiSha.Web/YiSha.Admin.Web/Controllers/HomeController.cs b/YiSha.Web/YiSha.Admin.Web/Controllers/HomeController.cs index d281cb3c..46d34bc8 100644 --- a/YiSha.Web/YiSha.Admin.Web/Controllers/HomeController.cs +++ b/YiSha.Web/YiSha.Admin.Web/Controllers/HomeController.cs @@ -67,13 +67,13 @@ public IActionResult Login() return View(); } - [HttpGet] - public async Task LoginOff() + [HttpPost] + public async Task LoginOffJson() { - #region 退出系统 OperatorInfo user = await Operator.Instance.Current(); if (user != null) { + #region 退出系统 // 如果不允许同一个用户多次登录,当用户登出的时候,就不在线了 if (!GlobalContext.SystemConfig.LoginMultiple) { @@ -95,9 +95,14 @@ public async Task LoginOff() Operator.Instance.RemoveCurrent(); new CookieHelper().RemoveCookie("RememberMe"); + + return Json(new TData { Tag = 1 }); + #endregion + } + else + { + throw new Exception("非法请求"); } - #endregion - return View(nameof(Login)); } [HttpGet] diff --git a/YiSha.Web/YiSha.Admin.Web/Views/Home/Index.cshtml b/YiSha.Web/YiSha.Admin.Web/Views/Home/Index.cshtml index 35bbd695..a9086e7d 100644 --- a/YiSha.Web/YiSha.Admin.Web/Views/Home/Index.cshtml +++ b/YiSha.Web/YiSha.Admin.Web/Views/Home/Index.cshtml @@ -129,7 +129,7 @@
  • - + 退出登录
  • @@ -203,4 +203,19 @@ maxmin: false }); } + + function loginOff() { + ys.ajax({ + url: '@Url.Content("~/Home/LoginOffJson")', + type: "post", + success: function (obj) { + if (obj.Tag == 1) { + location.href = '@Url.Content("~/Home/Index")'; + } + else { + ys.msgError(obj.Message); + } + } + }); + } diff --git a/YiSha.Web/YiSha.Web.Code/State/CookieHelper.cs b/YiSha.Web/YiSha.Web.Code/State/CookieHelper.cs index c3bd0c42..aa24147e 100644 --- a/YiSha.Web/YiSha.Web.Code/State/CookieHelper.cs +++ b/YiSha.Web/YiSha.Web.Code/State/CookieHelper.cs @@ -24,6 +24,7 @@ public void WriteCookie(string sName, string sValue, bool httpOnly = true) CookieOptions option = new CookieOptions(); option.Expires = DateTime.Now.AddDays(30); option.HttpOnly = httpOnly; + option.SameSite = SameSiteMode.Lax; hca?.HttpContext?.Response.Cookies.Append(sName, sValue, option); } @@ -40,6 +41,7 @@ public void WriteCookie(string sName, string sValue, int expires, bool httpOnly CookieOptions option = new CookieOptions(); option.Expires = DateTime.Now.AddMinutes(expires); option.HttpOnly = httpOnly; + option.SameSite = SameSiteMode.Lax; hca?.HttpContext?.Response.Cookies.Append(sName, sValue, option); }