Storing/Retrieving user data without database when using OWIN cookie authentication

谁都会走 提交于 2019-12-11 11:04:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!