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

Forums / Developing with Sitefinity / User roles and profiles

User roles and profiles

6 posts, 0 answered
  1. Iain
    Iain avatar
    26 posts
    Registered:
    29 Dec 2010
    11 Feb 2011
    Link to this post
    I have recently added a registration and login section to a site, the registration creates the user but when using the details to log in I receive the error 'page not served'. This is obviously due to the fact that the user hasnt been assigned a role, is there a snippet of code to add a role to a user on registration?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Feb 2011
    Link to this post
    Hello Iain,

    Here is a sample code

    var userManager = UserManager.GetManager("Default");
             System.Web.Security.MembershipCreateStatus status;
             userManager.Provider.SuppressSecurityChecks = true;
             var user = userManager.CreateUser("user1", "user1234@", "user1@test.com", "Question", "Answer", true, null, out status);
             user.FirstName = "FirstName";
             user.LastName = "LastName";
             userManager.SaveChanges();
     
     
             RoleManager roleManager = RoleManager.GetManager("AppRoles");
             roleManager.Provider.SuppressSecurityChecks = true;
             var role = roleManager.GetRole("Administrators");
             roleManager.AddUserToRole(user, role);
             roleManager.SaveChanges();


    Regards,
    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. Iain
    Iain avatar
    26 posts
    Registered:
    29 Dec 2010
    11 Feb 2011
    Link to this post
    Excellent thank you,

    I require to hold an extra field of data against the user, can I use meta fields or is there another method as these use the .NET controls?


    Thank you in advance
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Feb 2011
    Link to this post
    Hello Iain,

    We are working on an implementation for this. There is an implementation for Profiles that you can use, but we are going to remove it, so I suggest that you should wait for the SP1 when we will be ready with the new logic.

    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
  5. Iain
    Iain avatar
    26 posts
    Registered:
    29 Dec 2010
    16 Feb 2011
    Link to this post
    Thank you very much Ivan,

    I shall inform the client.

    Is there an ETA on SP1 or a case of keeping an eye on the site?


    Regards


    Iain
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Feb 2011
    Link to this post
    Hello Iain,

    I see that the post is opened for Sitefinity 3.x where we have this implementation, but I was referring to Sitefinity 4.0. So if  you are looking for 4.0, please check this post that will answer your question.

    Now, lets go back to Sitefinity 3.x. Below is a code that shows how to add a user to a role.

    UserManager manager = new UserManager("Sitefinity");
    var role = "Administrators";
    manager.AddUserToRole("username", role);

    To add extra fields to user you can use GetPropertyValue and SetPropertyValue methods that are expose by ASP.NET ProfileBase and ProfileCommon classes.


    All the best,
    Ivan Dimitrov
    the Telerik team
Register for webinar
6 posts, 0 answered