More in this section

Forums / Developing with Sitefinity / migrate asp.net membership tp sitefinity membership

migrate asp.net membership tp sitefinity membership

2 posts, 0 answered
  1. vinamra
    vinamra avatar
    45 posts
    Registered:
    23 Oct 2012
    28 May 2010
    Link to this post
    hi

    i am working on the project in which i have used default asp.net membeership
    not i want to intigrate that project with sitefinity

    is there any way by which i can transfer or migrate users from asp.net membership tables to sitefinity membership table.

    thanks.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    28 May 2010
    Link to this post
    Hi vinamra,

    1. You could create another connection string inside Sitefinity that points to the other database where you store the user's membership and role data.

    2. Register your custom membership and role providers in Sitefinty web.config - <membership> and  <roleManager>

    3. Create a simple page or control and copy the users from your custom provider to the Sitefinity provider

    Note that if you use Hashed password format you will not be able to migrate the old users. In case the password is Encrypted, you should decrypt it. The third format is Clear.


    Another option would be setting the additional provider as described above and moving the users during the authentication

    sample code

    void Login1_Authenticate(object sender, AuthenticateEventArgs e)
       {
           // the default provider should be set to Sitefinity !
           // authenticate the user through CustomProvider provider
           e.Authenticated = Membership.Providers["CustomProvider"].ValidateUser(this.Login1.UserName, this.Login1.Password);
       }
       void Login1_LoggedIn(object sender, EventArgs e)
       {
           // check whether there is a user in the default provider with the same name
           MembershipUser user = UserManager.Default.GetUser(this.Login1.UserName);
           if (user == null)
           {
               // if there is not a user with the same name create Membership user from the CustomProvider provider, so that
               // you can extract some data
               MembershipUser adUser = Membership.Providers["CustomProvider"].GetUser(this.Login1.UserName, false);
               // create the same user in the default Membership provider
               user = UserManager.Default.CreateUser(adUser.UserName, this.Login1.Password);
               UserManager userManager = new UserManager(this.Login1.MembershipProvider);
               // add then newly create user to a given role
               userManager.AddUserToRole(adUser.UserName, "administrators");
               // set the authentication cookie
               HttpCookie cookie = this.Response.Cookies[FormsAuthentication.FormsCookieName];
               UserManager.Default.SetAuthenticationCookie(cookie);
           }
       }


    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.
2 posts, 0 answered