I'm using asp.net Identity 2.0 for users to log into my website, where the authentication details are stored in an SQL database. Asp.net Identity has been implemented in a standard way as can be found in many online tutorials.
The ApplicationUser
class in IdentityModels
has been extended to include a custom property:
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType)
{
CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
return userIdentity;
}
//My extended property
public string Code { get; set; }
}
When I register a new user I pass the Code
custom property in the RegisterBindingModel
but I'm not sure how to insert this custom property to the WebUsers table.
I did as bellow but it doesn't actually inserting this property to the table together with the username and password.
var user = new ApplicationUser() { UserName = userName, Email = model.Email, Code=model.Code };
And the entire function:
[AllowAnonymous]
[Route("Register")]
public async Task<IHttpActionResult> Register(RegisterBindingModel model)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var userName = !string.IsNullOrEmpty(model.UserName) ? model.UserName : model.Email;
//I set it here but it doesn't get inserted to the table.
var user = new ApplicationUser() { UserName = userName, Email = model.Email, Code=model.Code };
IdentityResult result = await UserManager.CreateAsync(user, model.Password);
if (!result.Succeeded)
{
return GetErrorResult(result);
}
return Ok();
}
What am I missing? I was looking at similar questions but couldn't find an answer for this.