Groups | Blog | Home
all groups > vb.net > july 2003 >

vb.net : How can i found out the current user's role/permission level


MJB
7/24/2003 1:56:42 PM
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

Tom Vande Stouwe MCSD.net
7/24/2003 2:12:23 PM
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.
==========================================
[quoted text, click to view]

BenoitM
7/25/2003 9:09:46 AM
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);

-----


hope it helps


[quoted text, click to view]

AddThis Social Bookmark Button