473,320 Members | 2,112 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.

Check if user is a member of a domain group

I am writing a C#/asp.net app.I have a requirement to check if the user is
member of specific Domain group,how can this be accomplished?
I tried the following and it always returns false ,even if the user is part
of the group.
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
if(wp.IsInRole(@"Domain\group"))
{
MessageBox.Show("member",wp.Identity.Name);
}
else
{
MessageBox.Show("not menber",wp.Identity.Name);
}

TIA,
Vinny

Nov 19 '05 #1
1 3511
"Vinny Vinn" <Vi*******@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com...

Try this:

using System.DirectoryServices;

public bool IsUserInGroup(string pstrDomain, string pstrUser, string
pstrGroup)
{
try
{
DirectoryEntry objADEntry = new DirectoryEntry("WinNT://" + pstrDomain +
",domain");
DirectoryEntry objUser = objADEntry.Children.Find(pstrUser, "user");
DirectoryEntry objGroup = objADEntry.Children.Find(pstrGroup, "group");
return (bool) objGroup.Invoke("IsMember", new object[]
{objUser.Path.ToString()});
}
catch (Exception)
{
throw;
}
}

MessageBox.Show("not menber",wp.Identity.Name);

MessageBox.Show won't help you in ASP.NET... :-)
Nov 19 '05 #2

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

Similar topics

3
by: Jon Ley | last post by:
I am having a problem restricting write access to tables in my database. In my database I have a table called, for the sake of argument, 'TableX'. In my SQL Server Logins, I have set up a login...
9
by: Terry E Dow | last post by:
Howdy, I am having trouble with the objectCategory=group member.Count attribute. I get one of three counts, a number between 1-999, no member (does not contain member property), or 0. Using...
9
by: Jonny | last post by:
Hey all, I need to verify that a provided username is a Domain Administrator. Any idea's on how to do this? Thanks, Jonny -- /Jonny
0
by: Venkat | last post by:
Can any one tell me the way to check whether a given user name is a member of domain users or not. I do not know the domain name as well. I should retrieve from the logged in user, in which user...
0
by: Vinny Vinn | last post by:
I am writing a C#/asp.net app.I have a requirement to check if the user is member of specific Domain group,how can this be accomplished? I tried the following and it always returns false ,even if...
9
by: Sameh Ahmed | last post by:
Hello there Is there a way through dotNet to check if a certain user is a member of a specific group? I use ADSI to get the memberships of the user then compare them to the group I want to check,...
7
by: Sameh Ahmed | last post by:
Hello there IsInrole gives ya the means to check if the current or impersonated user belongs to a specific windows role or group. is there a way to do the same without using ADSI to check if...
10
by: Jeff Williams | last post by:
How can I get a list of the Groups both Local and Domain groups a User belongs to.
8
by: Michael Howes | last post by:
I have some code that manages local user logins. When I create a new user I want to set the password to expire every x days and the number of failed login attempts before the account is...
0
by: Uli Netzer | last post by:
Hi all, I'm trying to add a user from another domain (domain trust and rights are there) to a group in our domain. It's a domain local security group. I get the following errors: The server...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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

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.