I need to save New Claims value to my SQL Database [AspNetUserClaims]
table which I suppose can be done like this (please correct if I am wrong as I'm new to MVC).
The User logs in using OAuth
from Facebook. Once logged in, he fills in some form that collects user data as well as some uploads etc using a wizard type setup. Once the multi step wizard is completed in the View
, at the controller after POST
these fields are saved to the database. I need to save some of the fields data to the [AspNetUserClaims]
table which I suppose is possible in this way:
//Post Fields
var db = new ApplicationDbContext();
var Post = new PostModel();
Post.PostTitle = model.Post.PostTitle;
Post.PostBrief = model.Post.PostBrief;
db.PostModel.Add(Post);
db.SaveChanges();
// User Claims Data
var claims = new List<System.Security.Claims.Claim>();
claims.Add(new System.Security.Claims.Claim("FullName", model.UserClaims.FullName));
claims.Add(new System.Security.Claims.Claim("Email", model.UserClaims.Email));
System.Security.Claims.ClaimsIdentity i = (System.Security.Claims.ClaimsIdentity)HttpContext.GetOwinContext().Authentication.User.Identity;
i.AddClaims(claims);
//How to make the changes to User Claims, save to the database?