Solved

add a username to check in the follow function.

Posted on 2008-06-16
1
223 Views
Last Modified: 2010-04-15
I would like to modifiy the function below and check for the username in the group of members.

            string fullname = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
            string[] parts = fullname.Split('\\');
            string sDomain = parts[0];
            string sUser = parts[1];
            string sGroup = "gl ca corporate data";
            StringCollection groupMembers = this.GetGroupMembers(sDomain, sGroup, sUser);
 



I have a function that gets group members

 public StringCollection GetGroupMembers(string strDomain, string strGroup,  ?)
        {
            StringCollection groupMemebers = new StringCollection();
            try
            {
                DirectoryEntry ent = new DirectoryEntry(_path);
                DirectorySearcher srch = new DirectorySearcher("(CN=" + strGroup + ")");
                SearchResultCollection coll = srch.FindAll();
                foreach (SearchResult rs in coll)
                {
                    ResultPropertyCollection resultPropColl = rs.Properties;
                    foreach (Object memberColl in resultPropColl["member"])
                    {
                        DirectoryEntry gpMemberEntry = new DirectoryEntry("LDAP://" + memberColl);
                        System.DirectoryServices.PropertyCollection userProps = gpMemberEntry.Properties;
                        object obVal = userProps["sAMAccountName"].Value;
                        if (null != obVal)
                        {
                            groupMemebers.Add(obVal.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.Write(ex.Message);
            }
            return groupMemebers;
        }
0
Comment
Question by:mathieu_cupryk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 12

Accepted Solution

by:
jandromeda earned 500 total points
ID: 21801336
You can use this code.
bool isUserInRole = groupMembers.Contains(sUser);

Open in new window

0

Featured Post

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question