存储/无数据库检索用户数据使用OWIN Cookie身份验证时 [英] Storing/Retrieving user data without database when using OWIN cookie authentication

查看:90
本文介绍了存储/无数据库检索用户数据使用OWIN Cookie身份验证时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何正确地存储和检索属于用户数据使用OWIN Cookie身份验证时?没有数据库可用。数据应preferably可用只要该cookie仍然有效。如果这是不可能的,但如果用户需要重新登录再提供的数据,如果丢失是可以接受的。目前,登录名使用类似的东西做简单:

//这里检查凭据VAR索赔=新的List<权利要求GT; {新的索赔(ClaimTypes.Name,名)};VAR ID =新ClaimsIdentity(索赔,DefaultAuthenticationTypes.ApplicationCookie);。HttpContext.GetOwinContext()Authentication.SignIn(新AuthenticationProperties(){IsPersistent = isPersistent},身份);


解决方案

该Cookie中间件负责节能无论是在你的claimsidentity的,所以你可以自由地把你想要的任何数据转换成ClaimsIdentity,这将是适用于终身该cookie的。

How do I correctly store and retrieve data belonging to a user when using OWIN cookie authentication? No database is available. The data should preferably be available as long as the cookie remains valid. If that's not possible, it's acceptable if the user needs to re-login providing the data again if it is missing. Currently login is simply done using something similar to:

// Check credentials here

var claims = new List<Claim> { new Claim(ClaimTypes.Name, name) };

var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);

解决方案

The cookie middleware takes care of saving whatever is in your claimsidentity, so you are free to put whatever data you want into that ClaimsIdentity and it will be available for the lifetime of that cookie.

这篇关于存储/无数据库检索用户数据使用OWIN Cookie身份验证时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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