• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3061
  • Last Modified:

SP2010: How to check if current user exist in given AD group?

I have users who are on a AD group (ADGroup1) and I have a sharepoint group (SPGroup1) which has the above AD group . My question is: how do I check if current user is member of given AdGroup?

private Boolean isUserInGroup(SPGroup oGroupToTestFor, String sUserLoginName) 
    {    
        Boolean bUserIsInGroup = false; 
 
            SPUser oUser =null; 
            try{ 
                oUser = SPContext.Current.Web.AllUsers[sUserLoginName]; 
                } 
            catch{} 
            if(oUser!=null){ 
            foreach (SPUser item in oGroupToTestFor.Users) 
            { 
                if (item.UserToken == oUser.UserToken) 
                { 
                    bUserIsInGroup = true; 
                    break; 
                }                     
            } 
            } 
        return bUserIsInGroup;  
    } 

Open in new window

(http://stackoverflow.com/questions/1063931/sharepoint-check-if-a-user-is-member-of-a-group)

does not work if user exist on AD group (ADGroup1) which exist on sharepoint group (SPGroup1).

EDIT: This (http://chrissyblanco.blogspot.fi/2007/07/determining-whether-user-is-member-of.html) seems to be the answer.
0
tolppa
Asked:
tolppa
1 Solution
 
Rainer JeschorCommented:
Hi,
I would use the built-in options of
SPUtility.GetPrincipalsInGroup

Open in new window


MSDN:
http://msdn.microsoft.com/en-us/library/ms457726%28v=office.14%29.aspx

Ref:
http://stackoverflow.com/questions/4314767/getting-members-of-an-ad-domain-group-using-sharepoint-api

HTH
Rainer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now