【发布时间】:2017-01-26 02:50:39
【问题描述】:
我在 EF 端使用ASP.NET 核心身份我想将与用户相关的数据存储在身份验证 cookie 中。
这就是我过去使用ASP.NET 4.6 的方式(appcontext 是要存储的数据):
public static void IdentitySignin(AppContext appContext, string providerKey = null, bool isPersistent = false)
{
var claims = new List<Claim>();
// create *required* claims
claims.Add(new Claim(ClaimTypes.NameIdentifier, appContext.UserId.ToString()));
claims.Add(new Claim(ClaimTypes.Name, appContext.UserName));
// serialized AppUserState object
claims.Add(new Claim("appcontext" + EZA.Store.AppContext.Version, appContext.ToString()));
var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
// add to user here!
AuthenticationManager.SignIn(new AuthenticationProperties()
{
AllowRefresh = true,
IsPersistent = isPersistent,
ExpiresUtc = DateTime.UtcNow.AddDays(7),
}, identity);
}
但现在我将ASP.NET Identity 与EF 一起使用,但我找不到在cookie 中存储一些数据的方法。
【问题讨论】:
-
不确定您所说的“带有 EF 的 ASP.NET 身份”是什么意思 - 您指的是 this 之类的东西吗?
-
你得到它的工作伙伴了吗?
标签: asp.net asp.net-mvc entity-framework asp.net-core asp.net-identity