1

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
}
}
1
  • 1
    Did you ever get this working? Commented Mar 1, 2013 at 1:25

1 Answer 1

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");
4
  • I am looking for some solution for inside the runwithelevatedprivileges.
    – Ola
    Commented Feb 26, 2013 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. Commented Feb 26, 2013 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.
    – Ola
    Commented Feb 26, 2013 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. Commented Feb 27, 2013 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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