asp.net mvc 4 - Creating a custom role principal to be used with custom role provider, How do I get IIdentity to pass as parameter? -
i have custom role provider mvc4 application working in creates roles, checks role existence, check isuserinrole [authorize(roles = "admin")] still using default system.web.security.roleprincipal.isinrole(string role) method
i have tried create custom roleprincipal overrides isinrole method having problem finding correct parameter constructor , unsure how set in web.config. code follows:
using system; using system.collections.generic; using system.linq; using system.web; using system.configuration.provider; using metalearning.data; using system.web.security; namespace project.principal { public class myprincipal : system.web.security.roleprincipal { private mycontext dbcontext = new mycontext(system.configuration.configurationmanager.connectionstrings["mycontext"].connectionstring); private repository<myuser> userrepository; private repository<role> rolerepository; public myprincipal() { this.userrepository = new repository<myuser>(dbcontext); this.rolerepository = new repository<role>(dbcontext); } public override bool isinrole(string role) { role rolecheck = rolerepository.get(r => r.name == role).firstordefault(); myuser user = userrepository.get(u => u.username == httpcontext.current.user.identity.name).firstordefault(); user.roleid = rolecheck.roleid; userrepository.update(user); userrepository.savechanges(); return true; } }
}
i checked roleprincipal documentation http://msdn.microsoft.com/en-us/library/system.web.security.roleprincipal.aspx , can see basic constructor roleprincipal(iidentity) takes parameter of iidentity. how , can retrieved unsure is? there additional changes required in webconfig?
Comments
Post a Comment