The best approach to do this is not through session, just use the claims, and it will store the data in session cookies:
So you have to add claims at
IdentityModels class
then you have to write the claims in
GenerateUserIdentityAsync method
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
var userId = userIdentity.GetUserId();
var role = manager.GetRoles(userId);
// Add custom user claims here
userIdentity.AddClaims(new[] {
new Claim("Your claim name", Value that you want to store it)
});
return userIdentity;
}
Then you have to create a new class
public static class IdentityExtensions
{
public static Guid GetMyClaim(this IIdentity identity)
{
var claim = ((ClaimsIdentity)identity).FindFirst("Your claim name");
return (claim != null) ? claim.Value : string.Empty;
}
}
After this you can access it like this
User.Identity.GetMyClaim