asp.net mvc 4 - Creating User Accounts with SimpleMembershipProvider -


i'm using mvc 4 , i'm trying added new field userprofile named addedbyid (for house keeping).

here have:

websecurity.createuserandaccount(model.username, model.password, new                 {                     firstname = model.firstname,                     lastname = model.lastname,                     addeddate = datetime.utcnow                     addedbyid = // sure how id because account has not been created yet.                 }); 

should update addbyid after account created?

because support team create account someone.

if case, make sure addedbyid nullable, have support team authenticated first before create user.

then, make register action this;

    //     // post: /account/register      [httppost]     [allowanonymous]     [validateantiforgerytoken]     public actionresult register(registermodel model)     {         if (modelstate.isvalid)         {             // attempt register user             using (efdb db = new efdb())             {                                                      try                 {                     var userprofile = db.userprofiles.local.singleordefault(u => u.username == user.identity.name)                                 ?? db.userprofiles.singleordefault(u => u.username == user.identity.name);                          websecurity.createuserandaccount(                             model.username,                             model.password,                                 new                                     {                                         firstname = model.firstname,                                         lastname = model.lastname,                                         addeddate = datetime.utcnow,                                         addedbyid = userprofile.userid                                     }                             );                  catch (membershipcreateuserexception e)                 {                     modelstate.addmodelerror("", errorcodetostring(e.statuscode));                 }             }         }          // if got far, failed, redisplay form         return view(model);     } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -