How to Change the Profiles Primary Key
For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.
By default, Commerce Server 2007 stores Profiles data by using the email_address field as the primary key. Your business scenario may dictate that another field, such as logon_name, be the primary key. This topic outlines the steps that are required to change this default behavior, by using the starter site as an example. Follow all procedures in the order listed:
Change the Profiles System primary key.
Update the starter site configuration (if you are using the starter site).
Update the starter site Web pages (if you are using the starter site).
Update the Customer and Orders Manager tool.
Note
To perform the steps outlined in this procedure, you must first install the Commerce Server SDK. For more information about how to install the SDK, see the installation guide. By default, the SDK is installed in the C:\Program Files\Microsoft Commerce Server 2007\SDK folder.
Warning
Running the scripts in this procedure will delete all Profiles objects and tables. Therefore make sure that you back them up before following this procedure.
To change the Profiles System primary key to use logon_name
Open Microsoft SQL Server Management Studio and execute the following SQL script:
profilesql_nonemaillogonname.sql
By default, this is located in the C:\Program Files\Microsoft Commerce Server 2007\sdk\Samples\Profiles folder.
Import the Profilesql_nonemaillogonname.xml profile schema file. By default, this is located in the C:\Program Files\Microsoft Commerce Server 2007\sdk\Samples\Profiles folder. For information about how to import profile schema, see How to Import Profile Schema.
To update the Starter Site
Open the Web.config file for the starter site. By default, this folder is located in the C:\inetpub\wwwroot\StarterSite folder.
Change the value of the userIdKey attribute from "GeneralInfo.email_address" to "GeneralInfo.logon_name".
This attribute is located in the configuration/CommerceServer/profiles/userProfile node.
Add a new attribute that is named logonNameProperty, and assign it a value of "GeneralInfo.logon_name". This attribute is located in the configuration/system.web/membership/providers/add node (where the membership provider is UpmProvider). The node will look like the following:
<membership defaultProvider="UpmProvider"> <providers> <add name="UpmProvider" type="Microsoft.CommerceServer.Runtime.Profiles.UpmMembershipProvider" enablePasswordReset="true" logonNameProperty="GeneralInfo.logon_name"/> </providers> </membership>
To update the Starter Site Web pages
Open the StarterSite in Visual Studio 2005 or Visual Studio 2008.
Open the Register.aspx file, which is located in the User folder.
Change the value of the RequireEmail property to true. This property is located in the <asp:CreateUserWizard> control, and looks like the following:
<asp:Content ID="Content" ContentPlaceHolderID="MainContent" Runat="Server"> <asp:CreateUserWizard ID="NewUserForm" RequireEmail="true" OnCreatedUser="NewUserForm_CreatedUser" ... />
Locate the HTML code where the UserName row is defined in a table. After the closing </tr> tag for UserName, add the following code to create a new row in the table for Email:
<tr> <td align="right"> <asp:Label ID="EmailLabel" AssociatedControlID="Email" meta:resourceKey="EmailLabel" /></td> <td> <asp:TextBox ID="Email" MaxLength="64"></asp:TextBox> <asp:RegularExpressionValidator ID="EmailValidator" ControlToValidate="Email" ValidationGroup="NewUserForm" EnableClientScript="false" meta:resourceKey="EmailValidator">* </asp:RegularExpressionValidator> <asp:RequiredFieldValidator ID="EmailRequired" ControlToValidate="Email" ValidationGroup="NewUserForm" meta:resourceKey="EmailRequired">* </asp:RequiredFieldValidator> </td> </tr>
Remove the following <asp:RegularExpressionValidator> control from the page:
<asp:RegularExpressionValidator ID="UserNameValidator" ControlToValidate="UserName" ValidationGroup="NewUserForm" EnableClientScript="false" meta:resourceKey="UserNameValidator">* </asp:RegularExpressionValidator>
Save and close the Register.aspx file.
Open the Register.aspx.resx file, which is located in the User\App_LocalResources folder.
Remove these rows from the resources table:
UserNameValidator.ErrorMessage
UserNameValidator.ToolTip
Change these rows in the resources table to the specified values:
UserNameLabel.Text to "Logon name:"
UserNameRequired.ErrorMessage to "Please enter your logon name."
UserNameRequired.ToolTip to "Please enter your logon name."
Add the following rows in the resources table, and set them to the specified values:
EmailLabel.Text to "E-mail address:"
EmailRequired.ErrorMessage to "Please enter your e-mail address."
EmailRequired.ToolTip to "Please enter your e-mail address."
EmailValidator.ErrorMessage to "Please enter a valid e-mail address."
EmailValidator.ToolTip to "Please enter a valid e-mail address."
Save and close the Register.aspx.resx file.
Open the Register.aspx.cs file, which is located in the User folder.
In the OnLoad event, locate the following line:
this.NewUserForm.CreateUserStep.ContentTemplateContainer.FindControl("UserNameValidator")
Change the line to the following:
this.NewUserForm.CreateUserStep.ContentTemplateContainer.FindControl("EmailValidator")
Save and close the Register.aspx.cs file.
To update the Customer and Orders Manager tool
Locate the four *_presentationinfo_nonemaillogonname.xml files. By default, these are installed in the C:\Program Files\Microsoft Commerce Server 2007\sdk\Samples\Profiles folder. Each file is for a different culture; EN, DE, FR, and JA.
Copy the four files into the Profiles Web Service folder. By default this is C:\inetpub\wwwroot\ProfilesWebService.
Open the Profiles Web Service Web.config file by using Visual Studio or a text editor.
Change each of the <cultureConfig> elements in the <presentationConfiguration> section to point to the new presentation information file you copied in step 2, as follows:
<presentationConfiguration> <cultureConfig filePath="en_PresentationInfo_NonEmailLogonName.xml" isDefault="true"/> <cultureConfig filePath="de_PresentationInfo_NonEmailLogonName.xml"/> <cultureConfig filePath="fr_PresentationInfo_NonEmailLogonName.xml"/> <cultureConfig filePath="ja_PresentationInfo_NonEmailLogonName.xml"/> </presentationConfiguration>
Save and close the Web.config file.
Robust Programming
The procedure outlined in this topic shows how you can change the default Profiles System primary key from email_address to logon_name. However, you may have to change the primary key to a different field, such as tel_number. To do this, you must follow the same procedure as the one outlined in this topic, but you will have to modify the scripts and procedures shown in this topic.
Security
You must have permissions to execute SQL scripts and to import profile schema.