How can I add user First Name and Last Name to an ASP.NET Identity 2? -


i changed on use new asp.net identity 2. i'm using microsoft asp.net identity samples 2.0.0-beta2.

can tell me , how can modify code stores user first , last name along user details. part of claim , if how add ?

i assume need add here register method in account controller:

        if (modelstate.isvalid)         {             var user = new applicationuser { username = model.email, email = model.email };             var result = await usermanager.createasync(user, model.password);             if (result.succeeded)             {                 var code = await usermanager.generateemailconfirmationtokenasync(user.id);                 var callbackurl = url.action("confirmemail", "account", new { userid = user.id, code = code }, protocol: request.url.scheme);                 await usermanager.sendemailasync(user.id, "confirm account", "please confirm account clicking link: <a href=\"" + callbackurl + "\">link</a>");                 viewbag.link = callbackurl;                 return view("displayemail");             }             adderrors(result);         } 

also if did add first , last names stored in database? need create additional column in table information?

you'll need add applicationuser class if use identity samples, imagine have in identitymodels.cs

public class applicationuser : identityuser {     public async task<claimsidentity> generateuseridentityasync(usermanager<applicationuser> manager) {         // note authenticationtype must match 1 defined in cookieauthenticationoptions.authenticationtype         var useridentity = await manager.createidentityasync(this, defaultauthenticationtypes.applicationcookie);         // add custom user claims here         return useridentity;     } } 

after adding first , last names this:

public class applicationuser : identityuser {     public async task<claimsidentity> generateuseridentityasync(usermanager<applicationuser> manager) {         // note authenticationtype must match 1 defined in cookieauthenticationoptions.authenticationtype         var useridentity = await manager.createidentityasync(this, defaultauthenticationtypes.applicationcookie);         // add custom user claims here         return useridentity;     }      public string firstname { get; set; }     public string lastname { get; set; } } 

then when register user, need add them list defined in applicationuser class

var user = new applicationuser { username = model.email, email = model.email, firstname = "jack", lastname = "daniels" }; 

first , last names end in aspnetusers table after migrations


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -