IsPersistent 如何在 OWIN Cookie 身份验证中工作 [英] How IsPersistent works in OWIN Cookie authentication

查看:23
本文介绍了IsPersistent 如何在 OWIN Cookie 身份验证中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像不太明白IsPersistent在OWIN cookie认证中是如何工作的,下面的代码就是使用IsPersistent:

It seems I don't understand clearly how IsPersistent in OWIN cookie authentication works, the code below is to use IsPersistent:

var context = Request.GetOwinContext();
var authManager = context.Authentication;
var properties = new AuthenticationProperties { IsPersistent = isPersistence };

authManager.SignIn(properties, identity);

当用户选中/取消选中 Remember me(使用 IsPersistent 后面)时,我没有看到区别,因为如果我关闭 Chrome 浏览器并再次打开它以使用网站,cookie .AspNet.ApplicationCookie 仍然存在,即使我选中或取消选中 Remember me,它也能让我进入.

I don't see the difference when user checks/unchecks Remember me (uses IsPersistent behind) because if I close Chrome browser and open it again to go with the website, the cookie .AspNet.ApplicationCookie is still there and it lets me in even I check or uncheck Remember me.

我已经在 链接:

获取或设置身份验证会话是否在多个请求中持续存在.

Gets or sets whether the authentication session is persisted across multiple requests.

但是不要太理解,因为我看到它仍然有效.

But don't get much understanding since I see it still works.

设置 OWIN cookie 身份验证的代码:

The code to setup OWIN cookie authentication:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationMode = AuthenticationMode.Active,
    AuthenticationType = ApplicationTypes.ApplicationCookie,
    ExpireTimeSpan = TimeSpan.FromMinutes(30),
    LoginPath = new PathString("/Account/LogOn")
});

推荐答案

持久性 cookie 将作为文件保存在浏览器文件夹中,直到它们过期或手动删除.即使您关闭浏览器,这也会导致 cookie 持续存在.

Persistent cookies will be saved as files in the browser folders until they either expire or manually deleted. This will cause the cookie to persist even if you close the browser.

如果 IsPersistent 设置为 false,浏览器将获取会话 cookie,当浏览器关闭时该 cookie 会被清除.

If IsPersistent is set to false, the browser will acquire session cookie which gets cleared when the browser is closed.

现在重新启动浏览器后会话 cookie 无法清除的原因是因为 chrome 默认设置.要修复它,请转到 chrome settings -> advanced,然后取消选中 System 下的 Google Chrome 关闭时继续运行后台应用em> 部分.

Now the reason session cookie wont clear after restarting the browser is because of chrome default settings. To fix it go to chrome settings -> advanced, and uncheck Continue running background apps when Google Chrome is closed under System section.

这篇关于IsPersistent 如何在 OWIN Cookie 身份验证中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆