C# get list of AD groups for user

Posted on 2012-08-29
Medium Priority
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
  • 3
LVL 12

Expert Comment

ID: 38346944
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


Author Comment

ID: 38347006
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.

Accepted Solution

Eric3141 earned 0 total points
ID: 38369308
I solved this so closing this.

Author Closing Comment

ID: 38382357
I got help locally and solved this.

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

864 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