Lcng
Lcng

Reputation: 716

Persist user profile into cookie when using ASP.NET.Identity

When using forms authentication, we can persist anything we want into cookie by User Data. Now, I'm trying to use ASP.NET.Identity which almost has done everything related to Authentication for us. But it seems that it hasn't provide us a way to persist arbitrary User Data into cookie. Or maybe it is that I did not find it. Can any one help me? Thanks in advance, and sorry for my poor English.

Upvotes: 2

Views: 890

Answers (1)

jd4u
jd4u

Reputation: 5807

ASP.NET Identity provides support for Claims. You can utilize adding claims of profile information to the signin identity.

This is an example only.

var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
identity.AddClaim(new Claim("ProfileDATA", "VALUE"));
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);

Upvotes: 2

Related Questions