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);
' }
'} 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); ' } '} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |