473,471 Members | 2,040 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

enumerate roles a user belongs to ? (seek vb.net sample)

I would like to write a vb.asp.net function

Private Function fn_sGetRoles(byval sDelimiter as string) As
String

that simply returns a delimited list of all the roles a user belongs
to.

I did some research, and found a number of solutions, that all seem to
use a WindowsIdentity type object. However, when I try to convert
these to vb.net, on a line like

Dim wi As WindowsIdentity

I get this error

type 'WindowsIdentity' is not defined

What do I need to import for this?

Can someone post complete code to enumerate all the roles the given
user visiting my intranet page belongs to?

Thanks

Below are the 3 examples I found that supposedly do this, which I
can't get working:

'EXAMPLE #1:
'AppDomain domain = Thread.GetDomain();
'domain.SetPrincipalPolicy(PrincipalPolicy.Windows Principal);
'WindowsPrincipal principal =
(WindowsPrincipal)Thread.CurrentPrincipal;
'WindowsIdentity identity =
(WindowsIdentity)principal.Identity;
'Type idType;
'idType = identity.GetType();
'Object result = idType.InvokeMember(
' "_GetRoles",
' BindingFlags.Static | BindingFlags.NonPublic |
BindingFlags.InvokeMethod,
' null,
' identity,
' new object[]{identity.Token},
' null);

'string[] roles = (string[]) result;
'for (int i=0; i<roles.Length; i++)
' Console.WriteLine("Role: {0}", roles[i]);

'EXAMPLE #2:
'Dim wp As WindowsPrincipal = HttpContext.Current.User
'Dim id As WindowsIdentity = wp.Identity
'Dim idType As Type
'idType = GetType(WindowsIdentity)
'Dim result As Object = idType.InvokeMember("_GetRoles",
BindingFlags.Static Or BindingFlags.InvokeMethod Or
BindingFlags.NonPublic, Nothing, id, New Object() {id.Token}, Nothing)
'Dim roles() As String = DirectCast(result, String())
'Dim i As Integer
'For i = 0 To roles.Length - 1
' Response.Write("<br>" + roles(i))
'Next

'EXAMPLE #3:
'WindowsIdentity wi=WindowsIdentity.GetCurrent();
'Type typeWi=wi.GetType();
'try
'{
' string[] roles=(string[])typeWi.InvokeMember ("GetRoles",
'BindingFlags.NonPublic |
BindingFlags.InvokeMethod|BindingFlags.Instance,
'null,wi, new object [] {});
' foreach(string role in roles)
' Console.WriteLine (role);
' }
' catch(Exception ex)
' {
' Console.WriteLine(ex.Message);
' }
'}
Nov 18 '05 #1
1 3590
WindowsIdentity is located in : System.Security.Principal

Karl

"Mad Scientist Jr" <us*************@yahoo.com> wrote in message
news:7a**************************@posting.google.c om...
I would like to write a vb.asp.net function

Private Function fn_sGetRoles(byval sDelimiter as string) As
String

that simply returns a delimited list of all the roles a user belongs
to.

I did some research, and found a number of solutions, that all seem to
use a WindowsIdentity type object. However, when I try to convert
these to vb.net, on a line like

Dim wi As WindowsIdentity

I get this error

type 'WindowsIdentity' is not defined

What do I need to import for this?

Can someone post complete code to enumerate all the roles the given
user visiting my intranet page belongs to?

Thanks

Below are the 3 examples I found that supposedly do this, which I
can't get working:

'EXAMPLE #1:
'AppDomain domain = Thread.GetDomain();
'domain.SetPrincipalPolicy(PrincipalPolicy.Windows Principal);
'WindowsPrincipal principal =
(WindowsPrincipal)Thread.CurrentPrincipal;
'WindowsIdentity identity =
(WindowsIdentity)principal.Identity;
'Type idType;
'idType = identity.GetType();
'Object result = idType.InvokeMember(
' "_GetRoles",
' BindingFlags.Static | BindingFlags.NonPublic |
BindingFlags.InvokeMethod,
' null,
' identity,
' new object[]{identity.Token},
' null);

'string[] roles = (string[]) result;
'for (int i=0; i<roles.Length; i++)
' Console.WriteLine("Role: {0}", roles[i]);

'EXAMPLE #2:
'Dim wp As WindowsPrincipal = HttpContext.Current.User
'Dim id As WindowsIdentity = wp.Identity
'Dim idType As Type
'idType = GetType(WindowsIdentity)
'Dim result As Object = idType.InvokeMember("_GetRoles",
BindingFlags.Static Or BindingFlags.InvokeMethod Or
BindingFlags.NonPublic, Nothing, id, New Object() {id.Token}, Nothing)
'Dim roles() As String = DirectCast(result, String())
'Dim i As Integer
'For i = 0 To roles.Length - 1
' Response.Write("<br>" + roles(i))
'Next

'EXAMPLE #3:
'WindowsIdentity wi=WindowsIdentity.GetCurrent();
'Type typeWi=wi.GetType();
'try
'{
' string[] roles=(string[])typeWi.InvokeMember ("GetRoles",
'BindingFlags.NonPublic |
BindingFlags.InvokeMethod|BindingFlags.Instance,
'null,wi, new object [] {});
' foreach(string role in roles)
' Console.WriteLine (role);
' }
' catch(Exception ex)
' {
' Console.WriteLine(ex.Message);
' }
'}

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: poi | last post by:
What is a good way to enumerate all roles that a current ASP.NET user currently has? Using Windows Authentication, not Forms Auth. Thanks. *** Sent via Developersdex...
0
by: A. Elamiri | last post by:
I am building a portal for a college. I have offices and departments divided into groups, and within each group there is 3 different levels of Authority: Director Director Delegate Content...
7
by: Matthias S. | last post by:
Hi, here is what I'm trying to do: I have a virtual directory called "WebApp". Under this one I've got 2 physical directories called "Customers" and "Admins". I implemented Forms-based...
2
by: John | last post by:
Hi I am using the login control with a custom membership provider. My question is; once the user has logged in how do I programmatically check what roles the user belongs to, to provide the user...
3
by: charles | last post by:
Hi, I am trying to port my ASP application to ASP.Net 2.0 My application is sold to large corporations that have many thousands of users. So I do not use Forms authentication. To make it more...
2
by: Demetri | last post by:
I have several questions regarding the Membership and Roles mechanism in ASP.Net 2.0. 1. In the box, it comes with SqlMembershipProvider, which uses SQL Express 2005. What if I want it to use...
1
by: John | last post by:
Hi I have looked in help but am not clear how to do the following in vb.net code. 1. Check if a user belongs to a specific role. 2. Change user's password. Is it possible to do it without...
1
by: xeroxero | last post by:
What is the fastest way to enumerate roles for an ASP.NET 2.0 user? Authentication and authorization has occurred, and roles have been assigned to my (Generic)Principal. I just want to list them to...
0
by: Chris | last post by:
Hi, i have a problem with sitemap combined with roles. I already posted this but i reformulated simplier: here: there are two defined users: user1 and user2 there is one role: manager user1...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.