My requirement is when someone login to site and if he belong to 'owner' group it need to redirect immediately to specific site and if he belong to member group then need to navigate/redirect to same specified site other page.
Get user from sharepoint group and redirect
635 views Asked by Prasanth Nellore At
2
There are 2 answers
2
On
A very simple solution could be to use SPSecurityTrimmedControl. What it does is that it adds whatever is inside the control only if the specified access is fulfilled by the user.
So what you can do is that set the permissioning of the control to full control and include a simple redirect JavaScript. And just after that, outside the control, add a redirect script to other control. Something like below:
<SharePoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl1" runat="server" AuthenticationRestrictions="AuthenticatedUsersOnly" Permissions="ManageWeb" PermissionContext="CurrentSite">
<script type='text/javascript'>javascript to redirect owners</script>
</SharePoint:SPSecurityTrimmedControl>
<script type='text/javascript'>javascript to redirect readers</script>
So if the user is an owner, the owner redirect sscript will be present on the page and if not then it will redirect to the reader's page.
Since it is in SP2010, I assume we use server side C# code instead of CSOM, which is not matured yet in SP2010.
create a static helper method like:
public static bool IsInGroup(this SPUser user, SPGroup group) { return user.Groups.Cast() .Any(g => g.ID == group.ID); } }
verify in your code if the user belongs to certain group
SPUser user; SPGroup group; bool belongToGroup = user.InGroup(group);
use SPUtility.Redirect to redirect the user to any page you need.
Hope this helps somehow.