c# - Object Reference Error when adding Role to the User in ASP.NET Identity -


i developing asp.net mvc app , tried add role user following code:

        [httppost]         [validateantiforgerytoken]         public actionresult roleaddtouser(string username, string rolename)         {             applicationuser user = context.users.where(u => u.username.equals(username, stringcomparison.currentcultureignorecase)).firstordefault();             var account = new accountcontroller();             account.usermanager.addtorole(user.id, rolename);              viewbag.resultmessage = "role created !";              var list = context.roles.orderby(r => r.name).tolist().select(rr => new selectlistitem { value = rr.name.tostring(), text = rr.name }).tolist();             viewbag.roles = list;                 return view("manageuserroles");         }  

but when usermanager calls addtorole function gives object reference error in account controller in method in following code:

public applicationusermanager usermanager         {                         {                 return _usermanager ?? httpcontext.getowincontext().getusermanager<applicationusermanager>();             }             private set             {                 _usermanager = value;             }         } 

i have checked user.id , rolename parameters , ther not null.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -