至少在几年前,我一直在MVC解决方案中使用与此类似的代码...
[Authorize]
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
..........
然后输入我的验证码
myAuthenticationProperties = new Microsoft.Owin.Security.AuthenticationProperties();
myAuthenticationProperties.AllowRefresh = true;
myAuthenticationProperties.ExpiresUtc = DateTime.UtcNow.AddMinutes(60);
myAuthenticationManager.SignIn(myAuthenticationProperties, myClaimsIdentity);
return RedirectToAction("Index", "Home");
并且在我的初创公司..
public void Configuration(IAppBuilder app)
{
CookieAuthenticationOptions myAuthOptions = new CookieAuthenticationOptions();
myAuthOptions.AuthenticationType = "ApplicationCookie";
myAuthOptions.CookieHttpOnly = true;
myAuthOptions.SlidingExpiration = true;
myAuthOptions.LoginPath = new PathString("/Authentication/LogIn");
app.UseCookieAuthentication(myAuthOptions);
}
生活一直很花哨……直到最后两天。我一直到处乱走,试图找出为什么当我尝试登录时有时可以正常工作,而有时却只是挂起。使用一些调试消息,我发现我的身份验证过程已完成,但是当RedirectToAction发生时,什么也没有发生。.只是挂起。
然后我有了突破,我尝试使用IE和Edge,它似乎每次都起作用。只有Chrome挂起,并且至少在50%的时间内挂起。
我只能猜测,也许Chrome推出了一些不喜欢的更新?我完全不知所措...因此我为什么在这里。
Google对how Chrome handles cookies进行了更改,但没有SameSite
属性。以前,Chrome将未在Cookie上设置SameSite
属性与将SameSite=None
设置为相同,这意味着浏览器将接受所有cookie。现在,他们将其视为具有SameSite=Lax
,它将仅接受来自同一域的cookie。为了获得与旧方法相同的效果,必须将属性设置为SameSite=None; Secure
。