1

I cannot access a site through a zone that has custom membership provider set.

I get the following error

sorry this site hasn't been shared with you for custom

My CustomDbUsersMP class has the follwoing ValidateUser method below and it returns true:

public override bool ValidateUser(string username, string password)
        {
            bool isAuth = false;

            if (GenUtil.IsNull(username) || GenUtil.IsNull(password))
                return isAuth;
            else
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {

                    var dbUser = db.CustomDbUsersLists.Where(x => x.username.Trim().ToLower() == username.Trim().ToLower()).FirstOrDefault();

                    if (dbUser != null)
                        if (dbUser.password == password) // case sensitive
                            isAuth = true;

                });
            }

            return isAuth; // isAuth is true in debug
        }

My role provider class has the following code

 class CustomDbUsersRP : RoleProvider
  {

    private CustomDbUsersContextDataContext db = new CustomDbUsersContextDataContext(@"Data Source=MYLOCALSERVER\SharePoint;Initial Catalog=CustomDbUsers;Integrated Security=True;Enlist=False;Pooling=True;Min Pool Size=0;Max Pool Size=100;Connect Timeout=15");

    private string theRoleName = "DynamicAdmins";

    public override string[] GetUsersInRole(string roleName)
    {
        if (roleName.Trim().ToLower() != theRoleName.Trim().ToLower())
            return new string[] { };
        else
        {
            string[] users = new string[] { };

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {

                users = db.CustomDbUsersLists.Where(x => x.isadmin == 1).Select(x => x.username).ToArray<string>();

            });

            return users;

        }
    }

    public override bool IsUserInRole(string username, string roleName)
    {
        if (roleName.Trim().ToLower() != theRoleName.Trim().ToLower() ||
            GenUtil.IsNull(username))
            return false;
        else
        {

            bool ret = false;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                if (db.CustomDbUsersLists.Where(x => 
                        x.isadmin == 1 && 
                        x.username.Trim().ToLower() == username.Trim().ToLower())
                        .Any())
                    ret = true;
            });

            return ret;

        }
    }

    public override string[] GetAllRoles()
    {
        return new string[] { theRoleName };
    }

    public override string[] FindUsersInRole(string roleName, string usernameToMatch)
    {
        if (roleName.Trim().ToLower() != theRoleName.Trim().ToLower() ||
            GenUtil.IsNull(usernameToMatch))
            return new string[] { };
        else
        {
            string[] users = new string[] { };

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {

                users = db.CustomDbUsersLists.Where(x => 
                            x.isadmin == 1 && 
                            x.username.Trim().ToLower() == usernameToMatch.Trim().ToLower())
                            .Select(x => x.username).ToArray<string>();

            });

            return users;

        }
    }

    public override string[] GetRolesForUser(string username)
    {
        if (GenUtil.IsNull(username))
            return new string[] { };
        else
        {
            bool isAdmin = false;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                if (db.CustomDbUsersLists.Where(x =>
                        x.isadmin == 1 &&
                        x.username.Trim().ToLower() == username.Trim().ToLower())
                        .Any())
                    isAdmin = true;
            });

            if (isAdmin)
                return new string[] { theRoleName };
            else
                return new string[] { };

        }
    }

    public override bool RoleExists(string roleName)
    {
        return roleName.Trim().ToLower() == theRoleName.Trim().ToLower();
    }

    #region "NOT IMPLEMENTED"

    public override void AddUsersToRoles(string[] usernames, string[] roleNames)
    {
        throw new NotImplementedException();
    }

    public override string ApplicationName
    {
        get
        {
            throw new NotImplementedException();
        }
        set
        {
            throw new NotImplementedException();
        }
    }

    public override void CreateRole(string roleName)
    {
        throw new NotImplementedException();
    }

    public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
    {
        throw new NotImplementedException();
    }

    public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
    {
        throw new NotImplementedException();
    }

    #endregion

}

 }

I see in debug that the only method called is GetRolesForUser , which returns:

new string[] { theRoleName };

where theRoleName is a Group name that I have created on the site collection with EDIT permission

Is there anything else I should set to make the user enter?

0

The reason you're getting the message is because according to SharePoint, the user doesn't have permissions to access the site (though it is recognizing that the user has logged in).

First, to validate that, add that user to a built in group (Site Owners, or maybe as a site collection administrator). They should now be able to login. Once you verify that that works, you can remove them from the group and work on why they don't have permissions.

From what you describe, I believe the issue is the way that you've setup the permissions for the role. Adding a group with the same name as the role does not give permissions to that role. Instead you have to add the role to a SharePoint group with the appropriate permissions. You add them to the group the same as you would add a user, and when you search for the role name it should come up.

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.