.net - Roles management with no provider? -


in app need check roles loggind user determine if user see controls or not

first use loginview template ms don't have users db neither roles db couldn't add role provider couldn't use role class check users\role

as in case have session user info , roles has,and need perform check on roles set control enable user standard way "using .net built in class or code"

if want use parts of asp.net membership/authentication/authorisation services you'll need implement custom role provider perform role membership checking.

the first thing create class inherits system.web.security.roleprovider, in sounds methods you'll care implementing are:

  • findusersinrole
  • getrolesforuser
  • getusersinrole
  • isuserinrole

so, you'll end similar to:

using system;  using system.collections.generic;  using system.linq;  using system.web;  using system.web.security;  public class mycustomroleprovider : roleprovider {     public override string[] findusersinrole(string rolename, string usernametomatch)     {     }      public override string[] getrolesforuser(string username)     {     }      public override string[] getusersinrole(string rolename)     {     }      public override bool isuserinrole(string username, string rolename)     {         return getusersinrole(rolename).contains(username);     } } 

note: visual studio show lot of methods, such getallroles throws new notimplementedexception(), i've written "bare minimum" role provider , needed implement methods i've listed above. "read only" roles web app didn't update them though.

you'll need add rolemanager element web.config file under system.web follows:

<rolemanager defaultprovider="nameofyourroleprovider" enabled="true">     <providers>         <clear />          <add name="nameofyourroleprovider" type="namespace.to.your.class.and.class.name, name.of.assembly.containing.your.roleprovider" />     </providers> </rolemanager> 

one thing bear in mind roleprovider instance created underlying asp.net infrastructure you'll need access session data going via httpcontext.current.session (and checking httpcontext.current isn't null prior using it), require using system.web; in code provider.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -