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 want to redirect users from a landing page to another page in SharePoint 2010, based on their group membership. I need to do this using JavaScript (ECMAScript) and not server side code.

share|improve this question
add comment

6 Answers

You can get the group collection of a site and enumerate over it to find a specific group. You can then enumerate the members of the group to find the current user.

function onGetSharePointGroup() {
        var context = SP.ClientContext.get_current();
        var groupsEnum = this.groupCollection.getEnumerator();
        while (groupsEnum.moveNext()) {
            var group = groupsEnum.get_current();
            if (group.get_title() == "GROUP NAME TO FIND") {                    
                this.members = group.get_users();
                context.load(members);
            }
        }
        if (members != null) {
            context.executeQueryAsync(Function.createDelegate(this, this.FindCurrentUser), Function.createDelegate(this, this.onFailure));
        }
    }
share|improve this answer
add comment

You could wrap your redirect inside a SPSecurityTrimmedControl

<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="ViewListItems">
  ...Put your redirect in here...
</SharePoint:SPSecurityTrimmedControl>

Here are the values you can use for PermissionString.

If you want to find users that do NOT have a certain permission, this code would work better:

<script>
  var allowUserOnPage=false;
</script>
<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="ViewListItems">
  <script>
    allowUserOnPage=true;
  </script>
</SharePoint:SPSecurityTrimmedControl>
<script>
  if (!allowUserOnPage) {
    ...Put your redirect in here...
  }
</script>
share|improve this answer
    
I'm afraid this won't work for my scenario. I need it to be based on SharePoint group membership, not a permission string. –  Kelly Jones May 25 '11 at 4:10
add comment

You can look at http://spdailytips.blogspot.com/2011/09/check-current-user-permission.html

share|improve this answer
3  
Welcome to SharePoint! While this may theoretically answer the question, we prefer inclusion of the essential parts of the answer here, and to provide the link for reference. See How to Answer for general guidelines. –  Kit Menke Sep 9 '11 at 15:48
add comment

You can use a content editor web part for your script then use audience targeting on the webpart to determine what groups should see it.

share|improve this answer
add comment

You can get the groups in client side Silverlight app by calling the GetGroupCollectionFromUserAsync method of SharePoint's UserGroup.asmx web service. check out the link below for sample code.

http://www.innovawiz.com/get-the-sharepoint-groups-a-user-is-part-of-using-sharepoint-object-model

share|improve this answer
3  
Welcome to SharePoint.SE! Please read the comment I left on @spdailytips's answer above or see How to Answer for general guidelines. We recommend including the code sample in your answer in addition to providing the link. –  Kit Menke Apr 16 '12 at 17:34
add comment

You can actually do this using a generic HttpHandler and call from the client browser. Will share you some code sample later.

share|improve this answer
    
i doubt, it is not simply possible with ECMA script. –  Karthikeyan Jul 3 '11 at 12:30
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.