Export (0) Print
Expand All

Step 8: Add a New User Registration Page

Commerce Server 2002

In this step you will create a user registration page for the new users on your Web site. Using the registration page, users will create a login ID, specify their password, and any other custom attributes you specify.

To create a user registration page, you first create the UserRegistration.aspx Web form, and then add references to the Commerce Server 2002 objects as indicated in the following procedure.

In this step you will do the following:

  1. Insert Commerce Server classes.
  2. Design the UserRegistration.aspx page.
  3. Insert code into the submit_Click() handler.
  4. Insert code into the Page_Load() handler.
  5. Set UserRegistration.aspx as the start page.

To insert Commerce Server classes

To design the UserRegistration.aspx page

To insert code into the submit_Click() handler

To insert code into the Page_Load() handler

To set UserRegistration.aspx as the start page

To insert Commerce Server classes

  1. Click Start, point to Programs, point to Microsoft Visual Studio .NET, and then click Microsoft Visual Studio .NET.
  2. In the Microsoft Development Environment [design] – Start Page screen, click Open Project.
  3. In the Open Project dialog box, select the NorthwindTraders project, and then click Open.
  4. In the NorthwindTraders – Microsoft Visual C# .NET [design] – Default.aspx window, in the Solution Explorer - NorthwindTraders window, right-click NorthwindTraders, point to Add, and then click Add Web Form.
  5. In the Add new Item - NorthwindTraders dialog box, in the Name box, type UserRegistration.aspx, and then click Open.
  6. In the NorthwindTraders – Microsoft Visual C# .NET [design] – UserRegistration.aspx window, in the Solution Explorer - NorthwindTraders window, click View Code.
  7. In the NorthwindTraders – Microsoft Visual C# .NET [design] – UserRegistration.aspx.cs window, in the using section, add the following lines of code:
    using Microsoft.CommerceServer.Runtime;
    using Microsoft.CommerceServer.Runtime.Diagnostics;
    using Microsoft.CommerceServer.Runtime.Profiles;
    using System.Diagnostics;
    

To design the UserRegistration.aspx page

  1. In the NorthwindTraders – Microsoft Visual C# .NET [design] – UserRegistration.aspx window, click View on the toolbar, and then click Toolbox.
  2. In the Toolbox window, in the Web Forms section, drag and drop a Label object onto the form.
  3. In the Properties window, make sure the object you just created is selected, and then do the following:
    Use thisTo do this
    IDType userNameLabel.
    TextType Username:.
  4. In the Toolbox window, in the Web Forms section, drag and drop another Label object onto the form.
  5. In the Properties window, make sure the object you just created is selected, and then do the following:
    Use thisTo do this
    IDType passwordLabel.
    TextType Password:.
  6. In the Toolbox window, in the Web Forms, drag and drop another Label object onto the form.
  7. In the Properties window, make sure the object you just created is selected, and then do the following:
    Use thisTo do this
    IDType passwordRetypeLabel.
    TextType Confirm Password:.
  8. In the Toolbox window, in the Web Forms, drag and drop another Label object onto the form.
  9. In the Properties window, make sure the object you just created is selected, and then do the following:
    Use thisTo do this
    IDType firstNameLabel.
    TextType First Name:.
  10. In the Toolbox window, in the Web Forms, drag and drop another Label object onto the form.
  11. In the Properties window, make sure the object you just created is selected, and then do the following:
    Use thisTo do this
    IDType lastNameLabel.
    TextType Last Name:.
  12. In the Toolbox window, in the Web Forms, drag and drop another Label object onto the form.
  13. In the Properties window, make sure the object you just created is selected, and then do the following:
    Use thisTo do this
    IDType genderLabel.
    TextType Gender:.
  14. In the Toolbox window, in the Web Forms, drag and drop another Label object onto the form.
  15. In the Properties window, make sure the object you just created is selected, and then do the following:
    Use thisTo do this
    IDType userDescriptionLabel.
    TextType User Description:.
  16. In the Toolbox window, in the Web Forms, drag and drop another Label object onto the form.
  17. In the Properties window, make sure the object you just created is selected, and then do the following:
    Use thisTo do this
    IDType emailAddressLabel.
    TextType Email Address:.
  18. In the Toolbox window, in the Web Forms, drag and drop another Label object onto the form.
  19. In the Properties window, make sure the object you just created is selected, and then do the following:
    Use thisTo do this
    IDType messageLabel.
    TextClear the contents.
  20. Extend the messageLabel box across the bottom of the page.
  21. In the Toolbox window, in the Web Forms list, drag and drop a TextBox object onto the form, and place it right next to the Username label object.
  22. In the Properties window, make sure the object you just created is selected, and then in the ID property box type userName.
  23. In the Toolbox window, in the Web Forms list, drag and drop another TextBox object onto the form, and place it right next to the Password label object.
  24. In the Properties window, make sure the object you just created is selected, and then do the following:
    Use thisTo do this
    IDType password.
    TextModeSelect Password from the drop-down list.

    This option will hide the contents of the text box.

  25. In the Toolbox window, in the Web Forms list, drag and drop another TextBox object onto the form, and place it right next to the Confirm Password label object.
  26. In the Properties window, make sure the object you just created is selected, and then do the following:
    Use thisTo do this
    IDType passwordRetype.
    TextModeSelect Password from the drop-down list.

    The contents of the text box will be hidden.

  27. In the Toolbox window, in the Web Forms list, drag and drop a TextBox object onto the form, and place it right next to the First Name label object.
  28. In the Properties window, make sure the object you just created is selected, and then in the ID property box type firstName.
  29. In the Toolbox window, in the Web Forms list, drag and drop a TextBox object onto the form, and place it right next to the Last Name label object.
  30. In the Properties window, make sure the object you just created is selected, and then in the ID property box type lastName.
  31. In the Toolbox window, in the Web Forms list, drag and drop a TextBox object onto the form, and place it right next to the Email Address label object.
  32. In the Properties window, make sure the object you just created is selected, and then in the ID property box type emailAddress.
  33. In the Toolbox window, in the Web Forms list, drag and drop a DropDownList object onto the form, and place it right next to the User Description label object.
  34. In the Properties window, make sure the object you just created is selected, and then in the ID property box type userDescription.
  35. In the Toolbox window, in the Web Forms list, drag and drop a DropDownList object onto the form, and place it right next to the Gender label object.
  36. In the Properties window, make sure the object you just created is selected, and then in the ID property box type gender.
  37. In the Toolbox window, in the Web Forms list, drag and drop a Button object onto the form.
  38. In the Properties window, make sure the object you just created is selected, and then do the following:
    Use thisTo do this
    IDType submit.
    TextType Submit.

To insert code into the submit_Click() handler

  1. In the NorthwindTraders – Microsoft Visual C# .NET [design] – UserRegistration.aspx window, double click the Submit button.
  2. In the NorthwindTraders – Microsoft Visual C# .NET [design] – UserRegistration.aspx.cs window, enter the following code in the submit_Click() event handler:
    // First, we need to see if there is already a user 
    // by that name on the site. If there is, we will 
    // need to error out but leave the fields filled
    // in with the same data that they currently contain.
    AuthenticationInfo authInfo = CommerceContext.Current.AuthenticationInfo;
    ProfileContext profContext = CommerceContext.Current.ProfileSystem;
    Profile prof;
    
    try
    {
    // Having checked to see if there already is a user
    // with that name on the site, we now need to create
    // the new user account and populate its profile.
    // Also, check to make sure that the passwords are
    // the same.
    if ((String.Compare(passwordRetype.Text, password.Text) == 0))
    {
       
    // Get the profile context and fill it with our data.
       prof = profContext.CreateProfile(userName.Text, "UserObject");
       prof.Properties["GeneralInfo.logon_name"].Value = userName.Text;
       prof.Properties["GeneralInfo.user_security_password"].Value = password.Text;
       prof.Properties["GeneralInfo.first_name"].Value = firstName.Text;
       prof.Properties["GeneralInfo.last_name"].Value = lastName.Text;
       prof.Properties["GeneralInfo.email_address"].Value = emailAddress.Text;
       prof.Properties["AccountInfo.account_status"].Value = 1; 
       prof.Properties["AccountInfo.date_registered"].Value = DateTime.Now;
       prof.Properties["GeneralInfo.u_gender"].Value = (string) gender.SelectedItem.Value;
       prof.Properties["GeneralInfo.u_userDescription"].Value = (string) userDescription.SelectedItem.Value;
       prof.Update();
    
       // Set the authorization ticket.
       string userID = (string)prof.Properties["GeneralInfo.user_id"].Value;
       authInfo.SetAuthTicket(userName.Text, true, 200);
       authInfo.SetProfileTicket(userName.Text, true);
    
       messageLabel.Text = "";
       Response.Redirect("default.aspx");
    }
    else
    {
       messageLabel.Text = "Password does not match";
    }
    }
    catch(Exception exp)
    {
       // This means that this is a brand new name!
       messageLabel.Text = exp.Message; }
             
    

To insert code into the Page_Load() handler

  • In the NorthwindTraders – Microsoft Visual C# .NET [design] – UserRegistration.aspx.cs window, enter the following code in the Page_Load() event handler:
    // In here, we need to load the DropDownLists with the data
    // from the site terms.
    ProfileContext profContext = CommerceContext.Current.ProfileSystem;
    SiteTerm genderTerm = profContext.GetSiteTerm("u_gender");
    SiteTerm userDescriptionTerm = profContext.GetSiteTerm("u_userDescription");
    
    if (gender.Items.Count == 0)
    {
       gender.Items.Add(new ListItem("",""));
       foreach(SiteTermElement item in genderTerm.Elements)
       {
          ListItem li = new ListItem(item.Name,item.Value);
          gender.Items.Add(li);
       }
    }
    if (userDescription.Items.Count == 0)
    {
       userDescription.Items.Add(new ListItem("",""));
       foreach(SiteTermElement item in userDescriptionTerm.Elements)
       {
          ListItem li = new ListItem(item.Name,item.Value);
          userDescription.Items.Add(li);
       }
    }
    

    The new registration page is created.

To set UserRegistration.aspx as the start page

  1. In the NorthwindTraders – Microsoft Visual C# .NET [design] – UserRegistration.aspx.cs window, in the Solution Explorer - NorthwindTraders window, right-click UserRegistration.aspx, and then select Set As Start Page.
  2. Press F5 to build and execute the project.

Copyright © 2005 Microsoft Corporation.
All rights reserved.
Show:
© 2014 Microsoft