简体   繁体   English

使用OWIN Cookie身份验证时无需数据库即可存储/检索用户数据

[英]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.

相关问题 OWIN Cookie验证 - OWIN Cookie Authentication 在同一个MVC应用程序中使用OWIN Cookie身份验证和Windows身份验证 - Using both OWIN Cookie Authentication and Windows Authentication in the same MVC application 没有ASP.NET标识的OWIN cookie身份验证 - OWIN cookie authentication without ASP.NET Identity 在类内部从数据库存储/检索数据时的最佳实践 - Best practice when storing/retrieving data from database inside class Cookie 持久性在 OWIN 身份验证中不起作用 - Cookie persistence not working in OWIN authentication 在不使用外部数据库的情况下为会话存储数据 - storing data for the session without using external database owin认证的当前用户 - Current user in owin authentication 使用EF和Linq从数据库检索数据时访问Identity用户的其他属性 - Accessing additional properties of an Identity user when retrieving data from the database using EF and Linq 在 asp.net 核心中的每个请求中将用户数据存储在 session 存储中还是从数据库中检索? - Storing user data in session store or retrieving from database in each request in asp.net core? asp.net中的Owin身份验证和声明如何访问用户数据 - Owin Authentication and claims in asp.net how to access user data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM