c# - Assigning Roles in AspNetUserRoles table made by Identity -


i don't understand how work identity thing, below tried best, don't have errors doing nothing , wonder why. checked this:

adding role dynamically in new vs 2013 identity usermanager

add user role asp.net identity

table in database modified have: id (auto-increment, primary key), roleid, userid - both default , without primary key.

 protected void createuserwizard1_createduser(object sender, eventargs e)     {          // default userstore constructor uses default connection string named: defaultconnection         var userstore = new userstore<identityuser>();         var rolestore = new rolestore<identityrole>();         var manager = new usermanager<identityuser>(userstore);           var rolemanager = new rolemanager<identityrole>(rolestore);          var user = new identityuser { username = createuserwizard1.username };         var role = new identityrole { id = radiobuttonlist1.selectedvalue};          //create new user , try store in db.          if (createuserwizard1.password.tostring() == createuserwizard1.confirmpassword.tostring())         {             try             {                 identityresult result = manager.create(user, createuserwizard1.password.tostring());                 if (result.succeeded)                 {                         var authenticationmanager = httpcontext.current.getowincontext().authentication;                     var useridentity = manager.createidentity(user, defaultauthenticationtypes.applicationcookie);                      var selectedrole = radiobuttonlist1.selectedvalue;                      var currentuser = manager.findbyname(user.username);                     var roleresult = manager.addtorole(currentuser.id, selectedrole);                      authenticationmanager.signin(new authenticationproperties(), useridentity);                     .                     . 

i not looking classic solution made visual studio. have user profiles sql , working fine, roles messed up. working fine if put manually in sql table roleid , userid thought.

did try using other userstore constructor , other rolestore constructor.

they both accepting database context parameters.

in both links provided constructor parameter used.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -