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

Forums / Developing with Sitefinity / Creating Users with Sitefinity API

Creating Users with Sitefinity API

4 posts, 0 answered
  1. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    14 Apr 2010
    Link to this post
    Hi,

    I have a website developed with Sitefinity 3.7 which has a functionality of user registration. We have used the Sitefinity framework to store the registered user information and their profiles, as in, we save those users as CMS users and map them to a specific role created for users registering on the website. Now I have a requirement where I need to migrate an existing user data to the new website database. I'm developing a small application which will do the same. Through that application I want to add the existing users (of the old website) to the new user database as CMS users. For the same I've referenced 4 libraries that are available with Sitefinity - Telerik.Security, Telerik.DataAccess, Telerik.Framework and Nolics.Engine.v4.2. I'm also using the UserManager class to achieve the same. But i'm still not able to achieve the objective.

    Can you please help me out ?

    P.S. : the purpose of using the CMS framework for storing the registered users is that we didn't want to build a custom framework to handle the same.

    Thanks,
    Saumitra
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    14 Apr 2010
    Link to this post
    Hi Saumitra,

    You could use the methods that are referenced from the provider

    •         UserManager.Default.CreateUser();
    •         UserManager.Default.CreateRole();
    •         UserManager.Default.DeleteUser();
    •         UserManager.Default.UpdateUser();
    •         UserManager.Default.DeleteRole();
    Additionally you could use all method that expose ASP.NET MembershipUser, Membership, Role, ProfileBase classes.

    Kind 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. Saumitra
    Saumitra avatar
    127 posts
    Registered:
    10 Mar 2009
    14 Apr 2010
    Link to this post
    Hi,

    I would like to elaborate on the issue I'm facing:

    1) I'm trying to create a user from an external application, which is a windows application. Hence the configuration file is not similar to the web.config used by my website developed in sitefinity. Following is the entire app.config that I have for the windows app:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <connectionStrings>
        <clear/>
        <add name="PersonalFN" connectionString="Data Source=ILSQL2008; Initial Catalog=PersonalFN; Integrated Security=true;" />
      </connectionStrings>
      <system.web>
        <membership defaultProvider="PFNUsers" >
          <providers>
            <clear/>
            <add name="PFNUsers"
                 type="Telerik.DataAccess.AspnetProviders.TelerikMembershipProvider, Telerik.DataAccess"
                 applicationName="/"
                 connectionStringName="PersonalFN"
                 enablePasswordRetrieval="false"
                 enablePasswordReset="true"
                 requiresUniqueEmail="false"
                 requiresQuestionAndAnswer="false"
                 minRequiredPasswordLength="3"
                 minRequiredNonalphanumericCharacters="0"
                 passwordFormat="Hashed" />
          </providers>
        </membership>
      </system.web>
    </configuration>

    Am I missing something ?

    2) Following is the code I've written for adding the users:
    01.try
    02.           {
    03.               string sQuery = "SELECT PFNDirectUsers.*, PFNDirectPasswords.EncrPwd as Password FROM PFNDirectusers INNER JOIN PFNUsers ON ";
    04.               sQuery += "UPPER(PFNDirectUsers.Login) = UPPER(PFNUSers.sUserName) INNER JOIN PFNUserDetails ON ";
    05.               sQuery += "UPPER(PFNDirectUsers.FName) = UPPER(PFNUserDetails.sFirstName) AND ";
    06.               sQuery += "UPPER(PFNDirectUSers.LName) = UPPER(PFNUserDetails.sLastName) ";
    07.               sQuery += "AND PFNUsers.nUserId = PFNUserDetails.nUserId ";
    08.               sQuery += "INNER JOIN PFNDirectPasswords ON PFNDirectUsers.ClientCode = PFNDirectPasswords.ClientCode ";
    09.               sQuery += "WHERE RTRIM(LTRIM(PFNDirectUSers.Login)) <> '' ";
    10.               sQuery += "AND PFNDirectUSers.Login IS NOT NULL ORDER BY ClientCode";
    11.               SqlDataAdapter daStep1 = new SqlDataAdapter(sQuery, sConPFN);
    12.               DataSet dsStep1 = new DataSet();
    13.               daStep1.Fill(dsStep1);
    14.               if (dsStep1.Tables[0].Rows.Count > 0)
    15.               {
    16.                   foreach (DataRow drStep1 in dsStep1.Tables[0].Rows)
    17.                   {
    18.                       MembershipUser newUser = UserManager.Default.GetUser(drStep1["Login"].ToString());
    19.                       if (newUser == null)
    20.                       {
    21.                           string sPassword = drStep1["Password"].ToString();
    22.                           SqlCommand cmdPassword = new SqlCommand();
    23.                           cmdPassword.Connection = sConPFN;
    24.                           cmdPassword.CommandType = CommandType.StoredProcedure;
    25.                           cmdPassword.CommandText = "PFN_Decrypt_Password";
    26.                           cmdPassword.Parameters.Add("@PWD", SqlDbType.VarChar, 100);
    27.                           cmdPassword.Parameters[0].Value = sPassword;
    28.                           sPassword = (string)cmdPassword.ExecuteScalar();
    29.                           newUser = UserManager.Default.CreateUser(drStep1["Login"].ToString(), sPassword);
    30.                       }
    31.                   }
    32.               }
    33.           }
    34.           catch (Exception exp)
    35.           {
    36.               MessageBox.Show(exp.Message,"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    37.           }

    On line number 18, i get an error "Object reference not set to an instance of an object".

    3) Following is the stack trace:

       at Telerik.Security.UserManager..ctor(String providerName)
       at Telerik.Security.UserManager..ctor()
       at Telerik.Security.UserManager.get_Default()
       at PFN.DataMigration.UserMigration.btnStep1_Click(Object sender, EventArgs e) in D:\Work\Projects\Personalfn\New Website\Data Migration\User Migration\UserMigration\UserMigration.cs:line 53

    I hope this clarifies the issue I'm facing.

    Thanks,
    Saumitra
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    14 Apr 2010
    Link to this post
    Hello Saumitra,

    If you are using an external application, then you have to create a web service and host it on the Sitefinity website. Then you should call this service from your external application. Our blogs contain several examples on creating web services and consuming them. You might want to check out these couple of articles:
    Implementing scheduled services in Sitefinity 3.x
    Use the Content Manager API in a Web Service

    Sincerely yours,
    Radoslav Georgiev
    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