重构代码:精简Login写法,此处注意不能使用this.SignIn方法,此方法不进行Cookie的写入仅仅返回一个SignInResult

This commit is contained in:
Argo-MacBookPro 2018-09-16 13:23:26 +08:00
parent 7a36c338d6
commit 9574073355
1 changed files with 3 additions and 2 deletions

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
@ -42,8 +43,8 @@ namespace Bootstrap.Admin.Controllers
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), new AuthenticationProperties() { IsPersistent = remember == "true" });
}
// redirect origin url
var originUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter];
return Redirect(originUrl.Count == 1 ? originUrl[0] : "~/");
var originUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].FirstOrDefault() ?? "~/Home/Index";
return Redirect(originUrl);
}
/// <summary>
/// Logout this instance.