473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Roles

Is there a way in Windows Authentication to list ALL the domain roles that a
user is a part of? The syntax below only allows you to check if the user is
in a single specified role ...

User.IsInRole("whatever").ToString()

Thanks in advance!
Mark
Nov 18 '05 #1
3 1762
Hi Mark,

Yeah there is but it is not pretty... you'll need reflection to access
private parts that Microsoft in all it's wisdom hid from us hack- (sorry)
developers.

Here's my function for it:

public static string[] GetRoles(WindowsIdentity identity)
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
try
{
principal.IsInRole(WindowsBuiltInRole.User); // Ensure roles are loaded.
FieldInfo field = typeof(WindowsPrincipal).GetField("m_roles",
BindingFlags.NonPublic | BindingFlags.Instance);
return (string[])field.GetValue(principal);
}
catch (Exception err)
{
throw new Exception("Cannot determine roles.", err);
}
}

Hope this helps,
Michel
"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:e1**************@tk2msftngp13.phx.gbl...
Is there a way in Windows Authentication to list ALL the domain roles that a user is a part of? The syntax below only allows you to check if the user is in a single specified role ...

User.IsInRole("whatever").ToString()

Thanks in advance!
Mark

Nov 18 '05 #2
Beautiful. Thanks for the code - works swell.

I had previously been using forms authentication, but have now moved to a
Windows Domain with Active Directory. Should I be using the
WindowsPrincipal and WindowsIdentiy for all related security code and
tracking, or should I be sticking to ...

System.Security.Principal.IIdentity ii = User.Identity;

Thanks again.
Mark
"Michel" <ms*@virtualsciences.nl> wrote in message
news:br**********@reader10.wxs.nl...
Hi Mark,

Yeah there is but it is not pretty... you'll need reflection to access
private parts that Microsoft in all it's wisdom hid from us hack- (sorry)
developers.

Here's my function for it:

public static string[] GetRoles(WindowsIdentity identity)
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
try
{
principal.IsInRole(WindowsBuiltInRole.User); // Ensure roles are loaded. FieldInfo field = typeof(WindowsPrincipal).GetField("m_roles",
BindingFlags.NonPublic | BindingFlags.Instance);
return (string[])field.GetValue(principal);
}
catch (Exception err)
{
throw new Exception("Cannot determine roles.", err);
}
}

Hope this helps,
Michel
"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:e1**************@tk2msftngp13.phx.gbl...
Is there a way in Windows Authentication to list ALL the domain roles
that a
user is a part of? The syntax below only allows you to check if the
user is
in a single specified role ...

User.IsInRole("whatever").ToString()

Thanks in advance!
Mark


Nov 18 '05 #3
Hi Mark,

Nice to know, thanks.
Your question is one of design, more specifically do you want to be
"windows-specific" or not.
I guess it really depends on the environment you are in.

Cheers,
Michel

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Beautiful. Thanks for the code - works swell.

I had previously been using forms authentication, but have now moved to a
Windows Domain with Active Directory. Should I be using the
WindowsPrincipal and WindowsIdentiy for all related security code and
tracking, or should I be sticking to ...

System.Security.Principal.IIdentity ii = User.Identity;

Thanks again.
Mark
"Michel" <ms*@virtualsciences.nl> wrote in message
news:br**********@reader10.wxs.nl...
Hi Mark,

Yeah there is but it is not pretty... you'll need reflection to access
private parts that Microsoft in all it's wisdom hid from us hack- (sorry) developers.

Here's my function for it:

public static string[] GetRoles(WindowsIdentity identity)
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
try
{
principal.IsInRole(WindowsBuiltInRole.User); // Ensure roles are

loaded.
FieldInfo field = typeof(WindowsPrincipal).GetField("m_roles",
BindingFlags.NonPublic | BindingFlags.Instance);
return (string[])field.GetValue(principal);
}
catch (Exception err)
{
throw new Exception("Cannot determine roles.", err);
}
}

Hope this helps,
Michel
"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:e1**************@tk2msftngp13.phx.gbl...
Is there a way in Windows Authentication to list ALL the domain roles

that
a
user is a part of? The syntax below only allows you to check if the

user
is
in a single specified role ...

User.IsInRole("whatever").ToString()

Thanks in advance!
Mark



Nov 18 '05 #4

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

Similar topics

1
by: Mad Scientist Jr | last post by:
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...
5
by: hansiman | last post by:
Following http://aspnet.4guysfromrolla.com/articles/082703-1.aspx I've set up roles authentication for my web application. User's roles are registered by: HttpContext.Current.User = _ New...
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...
1
by: chris.rust | last post by:
Has anyone else had any trouble setting up a sitemap view to be filtered by roles? We've put a cust role provider in place, and we can verify that it's only being called once for each...
9
by: Mike Hofer | last post by:
BACKGROUND: We've designed a Website for a client that will be deployed across multiple physical locations. The site will be hosted from a corporate NOC, and administered by the IT group there. ...
1
by: jesibl | last post by:
Hi All, I have an ASP .NET 2.0 web based app which should change content based on a variable passed in the query string. Let's say the variable is called ID and the variations are A, B and C. ...
0
by: Douglas J. Badin | last post by:
Hi, The problem with Authorization is it stops at the first match and doesn't permit Grouping. On the Web Site, I am trying to Secure Page Access and SiteNaviagation by implementing the...
4
by: AC | last post by:
Hi there. My asp.net 2.0 development website uses roles to control access to sections of my site, configured using the asp.net configuration tool, which is great. Except that isn't available once...
0
by: sidhuasp | last post by:
Hi everyone I am using a mainmenu witeh sitemap provider with folowing sitemap <siteMapNode> <siteMapNode url="" title="Master Data" description="Enter Master data" roles ="Admin,PM"> ...
2
by: Nathan Sokalski | last post by:
When I call System.Web.Security.Roles.GetRolesForUser() it returns no results (an array of length 0) even though I have roles associated with the currently logged in user. I am able to get the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.