C# get list of AD groups for user

Posted on 2012-08-29
Last Modified: 2012-09-10
This code worked at a previous job but at this one when the webapp runs on the webserver then it does not pull back any groups for me.  When I run the app in Visual Studio then it retrieves a list of AD groups I have.

Any suggestions on what to tweak on our IIS webserver?  

    public static List<string> GetActiveDirectoryGroups()
        List<string> ADGroupList = new List<string>();

        foreach (System.Security.Principal.IdentityReference group in System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups)

        return ADGroupList;

Open in new window

Question by:Eric3141
    LVL 12

    Expert Comment

    I think that the problem is related to the user that is impersonated in IIS for the site where you need to run this page.

    When you run the project in Visual Studio, maybe your domain user is used to query the domain, but when you publish in IIS the default user is iusr_computername.

    Maybe the next page could help
    LVL 2

    Author Comment

    I looked at the article you referenced.  I'm not sure he's trying to do the same thing (or might be my lack of understanding of webservers).  I've created a database userid in SQL Server.  The webapp connection string uses that database userid.  

    In the article he seems to want to create a network userid for the webapp to use.

    Security to the webapp control is to be done by granting groups to the users in Active Directory.  The code should detect who is logged onto the machine and get a list of groups that logged on user has.

    This code worked at my last job -- I brought it with me to this one.  But I did not setup the IIS webserver there.

    The webconfig file is set to user impersonation.
    LVL 2

    Accepted Solution

    I solved this so closing this.
    LVL 2

    Author Closing Comment

    I got help locally and solved this.

    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

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video discusses moving either the default database or any database to a new volume.

    733 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

    25 Experts available now in Live!

    Get 1:1 Help Now