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.


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();
        if (members != null) {
            context.executeQueryAsync(Function.createDelegate(this, this.FindCurrentUser), Function.createDelegate(this, this.onFailure));

In this approach it is determined whether User belongs to specific Group and if so, then he/she is getting redirected to another page:

function isUserMemberOfGroup(userId, groupId, success,error) {

     var ctx = SP.ClientContext.get_current(); 
     var allGroups = ctx.get_web().get_siteGroups();
     var group = allGroups.getById(groupId);

        function(sender, args) {
            var userInGroup = findUserById(group.get_users(),userId);

       var findUserById = function(users,id){
           var found = false;
           var e =  group.get_users().getEnumerator();
           while (e.moveNext()) {
                var user = e.get_current();
                if (user.get_id() == id) {
                    found = true;
           return found; 



   var currentUserId = _spPageContextInfo.userId;
   var groupId = 4;  
   var defaultPageUrl = '/en/Pages/default.aspx';

   isUserMemberOfGroup(currentUserId, groupId, 
      function (isCurrentUserInGroup) {
          window.location.replace(defaultPageUrl); //redirect
         //Error handling goes here..

You've got a plenty of answer how to check permissions. If you want to check the group membership (it is of course not the same as permissions), then you have to check which groups the current user is member of and decide where to redirect.

Alternative 1 I have written a little example how to achieve this using jsom. Suppose you have a group called "Owners" and you want to redirect them to chuvash.eu (just for demo):

var desiredGroupTitle = "Owners";
var context = SP.ClientContext.get_current()
var web = context.get_web()
var user = web.get_currentUser()
var groups = user.get_groups()
context.load(groups, 'Include(Id, Title)');
context.executeQueryAsync(function() {
    var groupCount = groups.get_count();
    for(var i = 0; i < groups.get_count(); i++) {
        var group = groups.itemAt(i);
        var groupTitle = group.get_title();
        if (groupTitle === desiredGroupTitle) {

}, function() { 
    console.error("failed to check group membership for current user");

Alternative 2 Use REST api to get the current user's group membership. Here is the endpoint:


Here is a rest call using SP.RequestExecutor.js:

var desiredGroupTitle = "Owners";
var webUrl = _spPageContextInfo.webAbsoluteUrl;
var url = webUrl + '/_api/web/CurrentUser/Groups?$select=Id,Title';

var sodKey = 'sp.requestexecutor.js';
if (!_v_dictSod[sodKey]) {
    SP.SOD.registerSod(sodKey, '/_layouts/15/sp.requestexecutor.js');

SP.SOD.executeFunc(sodKey, "SP.RequestExecutor", function () {
    var executor = new SP.RequestExecutor(webUrl);
            url: url,
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: function(response) {
                var data = JSON.parse(response.body);
                var groups = data.d.results;

                for (var i = 0; i < groups.length; i++) {
                    if(groups[i].Title === desiredGroupTitle) {
            error: function() { 
                console.error("failed to check group membership for current user");

You could wrap your redirect inside a SPSecurityTrimmedControl

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

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:

  var allowUserOnPage=false;
<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="ViewListItems">
  if (!allowUserOnPage) {
    ...Put your redirect in here...
  • 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

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

  • 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

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.


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.


  • 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

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

  • i doubt, it is not simply possible with ECMA script. – Karthikeyan Jul 3 '11 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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