问题
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);
回答1:
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.
来源:https://stackoverflow.com/questions/22320632/storing-retrieving-user-data-without-database-when-using-owin-cookie-authenticat