+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Sitefinity 3.7 not adding user to roles

Sitefinity 3.7 not adding user to roles

4 posts, 0 answered
  1. Matthew
    Matthew avatar
    9 posts
    Registered:
    09 Jun 2009
    13 Jan 2011
    Link to this post
    I'm having a problem creating a new user.

    I have this code:

    UserManager users = UserManager.Default;

            MembershipUser user = users.CreateUser(username, password);
            if (!users.RoleExists("Salesforce"))
                users.CreateRole("Salesforce");
            if (!users.IsUserInRole(username, "Salesforce"))
                users.AddUserToRole(username, "Salesforce");

    The problem is, the user is created, but the user is not always added to the "Salesforce" role.  Most of the time it succeeds, but sometimes it doesn't.  Furthermore, it's not consistent with a particular username/password.  Sometimes that combination will add to the correct role, sometimes it won't, even though the user is always created.  No error is ever thrown.  What could be the problem?

    Thanks,
    Matthew
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jan 2011
    Link to this post
    Hi,

    Form this code snippet I cannot see what the problem would be unless some of the if conditions are "true" or  "false" .


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Matthew
    Matthew avatar
    9 posts
    Registered:
    09 Jun 2009
    13 Jan 2011
    Link to this post
    Sitefinity is providing these values.  It is either saying the value is false when it is true, or (more likely) it's simply not adding the user to the role for some reason.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jan 2011
    Link to this post
    Hello,

    OK, you can try to narrow down the issue by creating a custom class that inherits from TelerikRoleProvider and override AddUsersToRole


    // you should replace the parameters of User and Role with valid values from your application

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.DataAccess.AspnetProviders;
    using Nolics.ORMapper.Base;
     
    /// <summary>
    /// Summary description for Class8
    /// </summary>
    public class Class8 : TelerikRoleProvider
    {
         
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            Transaction tran = new Transaction();
            foreach (string roleName in roleNames)
            {
                Role role = new Role(Application, "test");
                if (role != null)
                {
                    foreach (string username in usernames)
                    {
                        User user = new User(Application,"sdasda", new Guid("");
                        if (user != null)
                        {
                            role.AddUser(user, tran);
                        }
     
                    }
                }
            }
            tran.Commit();
            Nolics.ORMapper.Base.DataConnection.InitWebRequest();
        }
     
        
    }

    Then call

    Class8 c = new Class8();
    c.AddUsersToRoles(params, params);

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered