Solved

add a username to check in the follow function.

Posted on 2008-06-16
1
216 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
1 Comment
 
LVL 12

Accepted Solution

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

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Default parameter problem in C# 3 25
C# Update Status Bar.... 1 22
Change data in datatable 8 13
Different Delete Messages 7 4
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now