重构代码:精简Login写法,此处注意不能使用this.SignIn方法,此方法不进行Cookie的写入仅仅返回一个SignInResult
This commit is contained in:
parent
7a36c338d6
commit
9574073355
|
@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
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" });
|
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), new AuthenticationProperties() { IsPersistent = remember == "true" });
|
||||||
}
|
}
|
||||||
// redirect origin url
|
// redirect origin url
|
||||||
var originUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter];
|
var originUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].FirstOrDefault() ?? "~/Home/Index";
|
||||||
return Redirect(originUrl.Count == 1 ? originUrl[0] : "~/");
|
return Redirect(originUrl);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logout this instance.
|
/// Logout this instance.
|
||||||
|
|
Loading…
Reference in New Issue