Hi.. This is a topic related to SharePoint security. When security levels drilling down to bottom level we always needs to have access permissions on web parts level. Basically we need to grant or deny access permission according SPGroups of who logged in to the system. So there are several ways to do that. One is to get the users groups from user object and manually check the specific group. You need couple of string operation and looping. Now that's kind of messy.
But SharePoint provides you an easy way of doing this this. You only need SPWeb object to do that operation. From this method you can easily find out whether current user is in the specific group. Method as follows.
This will worked on both Claim Based and Form Based users Well.. Thank You..
But SharePoint provides you an easy way of doing this this. You only need SPWeb object to do that operation. From this method you can easily find out whether current user is in the specific group. Method as follows.
SPWeb.IsCurrentUserMemberOfGroup(web.Groups["SpecificGroupName"].ID)The mehod requires the SPGroup id you want to search and returns Boolean value.You can use this method as follows
This method will give bool status TRUE if the user existing in provided group.
Just to remind that don't use this inside SPSecurity.RunWithElevatedPriviledges() because SharePoint gets the logged in user as System User.
This will worked on both Claim Based and Form Based users Well.. Thank You..