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.

Like if I open SharePoint site and I belong to Administrators then immediately I get redirected to SharePoint site home page and if I belong to Memebers then I get redirected to another page. Logic should be based on user name in SharePoint server 2010.

Do anyone have functionality for this JavaScript/any other code/programmatically for the same.

2 Answers 2


You can add a script editor webpart to the home page and add following script. This script checks if user belongs Members group and then redirects it to some other page. You can enhance it to check if user belongs to other groups.

<script type="text/javascript">
function IsCurrentUserMemberOfGroup(groupName, OnComplete) {

        var currentContext = new SP.ClientContext.get_current();
        var currentWeb = currentContext.get_web();

        var currentUser = currentContext.get_web().get_currentUser();

        var allGroups = currentWeb.get_siteGroups();

        var group = allGroups.getByName(groupName);

        var groupUsers = group.get_users();


        function OnSuccess(sender, args) {
            var userInGroup = false;
            var groupUserEnumerator = groupUsers.getEnumerator();
            while (groupUserEnumerator.moveNext()) {
                var groupUser = groupUserEnumerator.get_current();
                if (groupUser.get_id() == currentUser.get_id()) {
                    userInGroup = true;

        function OnFailure(sender, args) {

function CheckCurrentUerGroup() 
  IsCurrentUserMemberOfGroup("Members", function (isCurrentUserInGroup) {
        //Redirect to a certain page
        window.location = "http://addressOfPage;

ExecuteOrDelayUntilScriptLoaded(CheckCurrentUerGroup, 'SP.js');

Source: Check if user is in a specified group

  • thanks nadeem for this help and one more think i want starting to end functionality. Please explain Commented Feb 6, 2015 at 12:23
  • @PrasanthNellore What do you mean by start to end functionality? Commented Feb 6, 2015 at 12:34
  • where i can add this script and how to uplaod this script to my sharepoint site give steps please Commented Feb 9, 2015 at 7:52
  • @PrasanthNellore, it is mentioned in the answer, you can add in ScripEditorWebpat or you can also edit the page where you need it in sharepoint designer and add the script there. Commented Feb 9, 2015 at 8:07
  • in sps 2010 no script editor webpart in ribbon how to add and i want to add visual webpart for that? Commented Feb 9, 2015 at 9:14

Suppose you have two pages : 'OwnerPage' & 'MemberPage'

Write below code on your 'OwnerPage' Page_Load event :

SPUser currentUser = web.CurrentUser;
bool isExist = false;
string groupName = "Owner Group"; // Owner Group Name
isExist = IsUserMemberOfGroup(currentUser, groupName); // call function
   // stay on OwnerPage
   // redirect to MemberPage

Calling Function :

// Check that user in the Group or not
public static bool IsUserMemberOfGroup(SPUser user, string groupName)
            bool result = false;

if (!String.IsNullOrEmpty(groupName) && user != null) { foreach (SPGroup group in user.Groups) { if (group.Name == groupName) { // found it result = true; break; } } } return result; }
  • Welcomes @Prasanth Nellore , You can mark as 'Accept Answer' if you find the solution with this answer. Commented Feb 20, 2015 at 8:28

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.