在OWIN cookie认证如何IsPersistent作品 [英] How IsPersistent works in OWIN Cookie authentication

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

问题描述

看来我不清楚地了解如何 IsPersistent 在OWIN cookie认证的作品,下面的代码是使用 IsPersistent

  VAR背景= Request.GetOwinContext(); 
VAR authManager = context.Authentication;
VAR性能=新AuthenticationProperties {IsPersistent = isPersistence};

authManager.SignIn(属性,身份);



我看不出区别,当用户签入/取消选中记住我(使用 IsPersistent 后面),因为如果我关闭Chrome浏览器并打开它再次去的网站时,Cookie .AspNet .ApplicationCookie 仍然存在,它让我连我自己选中或取消选中记住



我已经检查 IsPersistent 定义上的链接




获取或设置是否验证会话坚持跨越多个请求。




但是,因为我看到它仍然工作没有得到太多的了解。



中的代码设置OWIN Cookie身份验证:

  app.UseCookieAuthentication(新CookieAuthenticationOptions 
{
AuthenticationMode = AuthenticationMode.Active,
AuthenticationType = ApplicationTypes.ApplicationCookie,
ExpireTimeSpan = TimeSpan.FromMinutes(30),
LOGINPATH =新PathString(/帐号/登录)
});


解决方案

永久Cookie会在浏览器文件夹中保存为文件直到他们要么到期或手动删除。这将导致即使你关闭浏览器的cookie来坚持。



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



现在的原因会话cookie重新启动浏览器后不会清楚是因为铬默认设置。
。要修复它去镀铬的设置的 - > 高级的,并取消选中继续运行后台应用时,谷歌Chrome关闭系统的部分。


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);

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.

I have checked the definition of IsPersistent on the link:

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

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

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")
});

解决方案

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.

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

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.

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

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