Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a sharepoint permission group with some permissionslevels. The name is: "SPProgress". Inside this group I have inserted a AD usergroup with the name "ADProgress".

I would like to check in code if the current user is exist in the SharePoint permision group "SPProgress". But if the current user is exist in the AD usergroup "ADProgress", it needs to return true.

I set the currentuser outside the RunWithElevatedPrivileges in a parameter.

SPUser currentUser = SPContext.Current.Web.CurrentUser;
SPGroup someGroup = somegroup...

SPSecurity.RunWithElevatedPrivileges(delegate()
                            {

if(IsUserExistInGroup(currentUser, someGroup ))
{
// do some logic
}
}
share|improve this question
1  
Did you ever get this working? –  Steve Lineberry Mar 1 '13 at 1:25
add comment

1 Answer 1

Since you are using CurrentUser and if you create the a SPWeb object outside of the runwithelevatedprivileges this code should work for you for the SharePoint group:

web.IsCurrentUserMemberOfGroup(someGroup.ID);

Since you are using the current user, this code should work for you for the AD group:

HttpContext.Current.User.IsInRole("domain\\ADProgress");
share|improve this answer
    
I am looking for some solution for inside the runwithelevatedprivileges. –  KHA Feb 26 '13 at 18:40
    
Why can't you run this within runwithelevatedprivileges??? Just use the web object created outside runwithelevatedprivileges so it will use the currently logged in user. –  Steve Lineberry Feb 26 '13 at 18:53
    
I am looking for some solution with SPUser and SPGroup as parameters. With these 2 parameters inside the RunWithElevatedPrivileges I would like to check the membership. –  KHA Feb 26 '13 at 19:20
    
Right, that should be fine. The issue comes with you CREATE the spweb or spsite object inside the runwithelevatedprivileges. When that happens the service account is what is assigned to the usertoken and when you try to check permissions they always return true. –  Steve Lineberry Feb 27 '13 at 14:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.