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

Forums / General Discussions / CreateUserWizardControl

CreateUserWizardControl

14 posts, 2 answered
  1. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    10 Aug 2010
    Link to this post
    I'm trying to implement the CreateUserWizard Control I downloaded from here: http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/createwizarduser-explains.aspx

    It seems that some assembly names have changed or are missing.
    Telerik.Security is now Telerik.Sitefinity.Security;

    but where are the methods AddUserToRole and SetProfileProperties for UserManager?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    10 Aug 2010
    Link to this post
    Hi Kristian,

     AddUserToRole is a methodof Telerik.Security.UserManager class.SetProfileProperties is a method of Telerik.Security.WebControls.ManageProfile class.

    Best wishes,
    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. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    10 Aug 2010
    Link to this post
    When trying to use Telerik.Security; I get

    The type or namespace name 'Security' does not exist in the namespace 'Telerik' (are you missing an assembly reference?)

    but Telerik.Sitefinity.Security works, but those methods aren't there, is this not yet included in 4.0?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    10 Aug 2010
    Link to this post
    Hi Kristian,

    These are methods for Sitefinity 3.x edition. The API for Sitefinity 4.0 is different. In 4.0 you can use Telerik.Sitefinity.Security.RoleManager and its AddUserToRole method.

    var provider = "RolePRovider";
    var manager = Telerik.Sitefinity.Security.RoleManager.GetManager(provider);
    manager.AddUserToRole(param1, param2);


    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. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    10 Aug 2010
    Link to this post
    Thanks, but now I receive this error

    The type SByte* does not have an accessible constructor.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.InvalidOperationException: The type SByte* does not have an accessible constructor.

    Source Error: 

    Line 36:     {
    Line 37:         var provider = "RoleProvider";
    Line 38:         var manager = RoleManager.GetManager(provider);

    Here is my code, also in the 3.x API to set the user name under profile properties you used
    this.ManageProfile.SetProfileProperties(CreateUserWizard1.UserName);

    I think the new method is this.Profile.SetPropertyValue  but i am not sure what the propertyName would be?

    void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        var provider = "RoleProvider";
        var manager = RoleManager.GetManager(provider);
     
        User user = new User();
        user.SetUserName(CreateUserWizard1.UserName);
     
        Role role = new Role();
     
        if (defaultRoles != null)
        {
            foreach (string roleProfile in defaultRoles)
            {
                role.Name = roleProfile;
                manager.AddUserToRole(user, role);
            }
        }
        //this.Profile.SetPropertyValue("UserName", user.UserName);
    }

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    10 Aug 2010
    Link to this post
    Hi Kristian,

    By default there are two providers - "Default" and "AppRoles". There is a third provider for LDAP. In your code you are passing "RoleProvider" to GetManager().

    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
  7. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    11 Aug 2010
    Link to this post
    Ah thank you! that helps

    what about the profile properties such as username?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    11 Aug 2010
    Link to this post
    Hi Kristian,

    You can use Telerik.Sitefinity.Security.UserManager - Represents an intermediary between users and membership data providers. and Telerik.Sitefinity.Security.Model.User class - The persistent membership user class used by OpenAccess membership provider.

    // getting user
             var manager = Telerik.Sitefinity.Security.UserManager.GetManager();
             var user =  manager.GetUsers().Where(u => u.FirstName == "foo");
             
             // creating user, setting properties
     
              System.Web.Security.MembershipCreateStatus status;
              var newUser = manager.CreateUser("username","pword", "email", "val", "val", true, null, out status);
              if (status == System.Web.Security.MembershipCreateStatus.Success)
              {
                  newUser.FirstName = "val";
                  newUser.LastName = "val";
                  manager.SaveChanges();
     
              }


    Best wishes,
    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
  9. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    11 Aug 2010
    Link to this post
    I'm not sure what Im doing wrong here, but I try that code and no user is created in the back end.
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    11 Aug 2010
    Link to this post
    Hello Kristian,

    Try using the default provider for UserManager. Verify that the status is "Success" otherwise the user will not be created. Note that the password must have special char in it

    System.Web.Security.MembershipCreateStatus status;
    var manager = UserManager.GetManager("Default");
    var newUser = manager.CreateUser("username", "username@username", "email@test.com", "val", "val", true, null, out status);
    if (status == System.Web.Security.MembershipCreateStatus.Success)
    {
        newUser.FirstName = "val";
        newUser.LastName = "val";
        manager.SaveChanges();
     
    }


    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
    Answered
  11. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    11 Aug 2010
    Link to this post
    Ah thank you, it was the special character in the password that was throwing me.
  12. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    12 Aug 2010
    Link to this post
    I have one more question, what do i need to do to retrieve an existing role and then add the user to the role.
    I tried using roleManager.GetRole("GUID#") and received 

    Value cannot be null.
    Parameter name: role




    EDIT:
    nevermind, was using the wrong name
  13. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    13 Aug 2010
    Link to this post
    when trying to use the wizard when not logged in, would there be some setting in the web.config to allow this?

    You are not authorized to 'Manage Users' ('Backend').

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.UnauthorizedAccessException: You are not authorized to 'Manage Users' ('Backend'). 

    ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. 

    To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    15 Aug 2010
    Link to this post
    Hello Kristian,

    By default anonymous users are not allowed to manage users. When you are not logged in, you are an anonymous user. You can grant needed rights for a given role from Settings  >> Permissions section of Sitefinity's backend.

    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
    Answered
14 posts, 2 answered