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
Post a Comment