473,385 Members | 1,752 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,385 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 1767
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.