How can i found out the current user's role/permission level

M

MJB

I know I can get the current username through the System.Environment class,
but I can't seem to find where I can retrieve the user's role / permission
level (i.e. Admin, power user, etc).

If anyone has done this and can shed some light on the issue I would
appreciate it.

TIA,
Matt
 
T

Tom Vande Stouwe MCSD.net

What you can get is the Groups that the user is in with theUser.IsInRole.
You will need to know what permission the groups have, but that is all that
is available to the IDE

Tom

--
==========================================
= Tom Vande Stouwe MCSD.net, MCAD.net, MCP
= 45Wallstreet.com (www.45wallstreet.com)
= (803)-345-5001
==========================================
= If you are not making any mistakes
..= ..you are not trying hard enough.
==========================================
 
B

BenoitM

in addition to what Tom said, with IsInRole , you must know the group name,
as there's no mechanism to retrieve all the group to which a user belongs.

you can use reflection to retrieve the list of all the groups a user belongs
to, but it should not be used in production app since it require elevated
previleges (bcoz of Reflection). Anyway it's a cool way to retrieve the
exact name of all the groups...

----- C# code ----

System.Security.Principal.WindowsIdentity WI =
System.Security.Principal.WindowsIdentity.GetCurrent();

System.Security.Principal.WindowsPrincipal WP = new
System.Security.Principal.WindowsPrincipal(WI);

Type TT = WP.GetType();
FieldInfo PI = TT.GetField( "m_roles",BindingFlags.NonPublic |
BindingFlags.Instance );

string[] ROLES = (string[])PI.GetValue(WP);
string AllRoles="";
foreach (string Role in ROLES)
{
AllRoles +=Role + "\n";
}
MessageBox.Show( AllRoles);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top