[英]Storing/Retrieving user data without database when using OWIN cookie authentication
How do I correctly store and retrieve data belonging to a user when using OWIN cookie authentication? 使用OWIN Cookie身份验证时,如何正确存储和检索属于用户的数据? No database is available.
没有可用的数据库。 The data should preferably be available as long as the cookie remains valid.
只要cookie保持有效,数据就应该最好可用。 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);
Cookie中间件负责保存您的Claimsidentity中的任何内容,因此您可以自由地将所需的任何数据放入ClaimsIdentity中,并且该数据在该Cookie的整个生命周期内都可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.