Commerce Server General - How to implement the UpmMembershipProvider in CS 2007

This is Interesting: Free IT Magazines  
Home > Archive > Commerce Server General > June 2006 > How to implement the UpmMembershipProvider in CS 2007





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How to implement the UpmMembershipProvider in CS 2007
Amy

2006-06-18, 7:19 am

The UpmMembership Provider extends the Membership framework offered by
ASP.Net to accommodate the use of the ASP.Net Login Controls and
authenticate against Commerce Server Profiles and according to Commerce
Server 2007 documentation is the recommended means of authentication
and password management.

1. Configuring the Commerce Server UserObject Profile

The Commerce Server UserObject profile must have at least the following
fields defined:

GeneralInfo.user_id: This field usually pre-configured if a sample or
starter site has been unpupped. It is of type GUID and must be
configured to be a unique key. This field is used to uniquely
identify the user.
GeneralInfo.security_password: This field stores the user password
GeneralInfo.email_address: This field stores the user email address.

Note: By default, the UpmMembership provider uses the
GeneralInfo.email_address as the logon name field. In this example, I
have created a new profile field called "GeneralInfo.logon_name" in
the UserObject Profile definition in Commerce Server and will implement
the UpmMembership provider to use this field as the logon name as
opposed to the GeneralInfo.emal_address field.

2. Configure the application to use Forms Authentication

In the web.config file in the <system.web> section, modify the
<authentication> tag as follows:
<authentication mode="Forms">
<forms name=".yourappname" loginUrl="yourloginurl.aspx" />
</authentication>

This will configure the Commerce Application to use forms
authentication.

3. Configuring the site to use the UpmMembership Provider

In the web.config file, add or update the <system.web><Membership>
section as follows:
<membership defaultProvider="UpmMembershipProvider">
<providers>
<clear />
<add applicationName="YourAppName"
enablePasswordRetrieval="false" enablePasswordReset="true"
logonNameProperty="GeneralInfo.logon_name"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="true" enableCreateDate="true"
enableEmailAddress="true"
enableLastLoginDate="true" profileDefinition="UserObject"

passwordFormat="Hashed" name="UpmMembershipProvider"
type="Microsoft.CommerceServer.Runtime.Profiles.UpmMembershipProvider"
/>
</providers>
</membership>

Items worthy of note here are:
defaultProvider attribute: This is the name of the provider that will
be used by default.
logonPropertyName: If not specified the provider will use
"GeneralInfo.email_address " by default. In this case a
"GeneralInfo.logon_name" field has been defined in the user object
profile and will be used to store the logon name.
name: This attribute identifies the provider. The value of this
attribute corresponds to the value of the "defaultProvider"
attribute specified in the "Membership" node.
type: This is the type name of the membership provider and in the case
of CS 2007 should be:
"Microsoft.CommerceServer.Runtime.Profiles.UpmMembershipProvider."

Note: These attributes are XML and are therefore case-sensitive.

There are various other attributes which can be configure here, the use
of which are defined in Membership Documentation for ASP.Net as well as
the Membership Documentation for Commerce Server.

4. Configuring the Commerce Server Profiles section

This section contains settings which configure the functionality of
profiles and catalogsets. This article will refer only to those
attributes applicable to the UpmMembershipProvider.
The <userProfile> node resides in the <CommerceServer><profiles> node
in the web.config

<userProfile profileDefinition="UserObject"
userIdProperty="GeneralInfo.user_id"
organizationIdProperty="AccountInfo.org_id"
catalogSetIdProperty="AccountInfo.user_catalog_set"

userIdSource = "ASP.Net"
userIdKey="GeneralInfo.logon_name"
userIdTarget="GeneralInfo.user_id"
/>

A brief description of these attributes and what they do follows:

profileDefinition: Refers to the Profile Definition defined in
Commerce Server which contains user profiles. This would usually be
"UserObject" but can be customized to use an alternative profile
definition.
userIdProperty: This attribute identifies the field which is a member
of the aforementioned profileDefinition which uniquely identifies the
user. By default this field is "GeneralInfo.user_id"
userIdSource: There are two possible values for this field, "UPM"
and "ASP.Net". When implementing the Membership provider, this
value should be configured to "ASP.Net" which is the default value.
userIdKey: In the Membership configuration section described in the
previous section, we configured the "logonPropertyName" field's
value to "GeneralInfo.logon_name". This property tells the
UpmMembershipProvider to store the logon name in this field in the
profile DB. The ASP.Net framework stores the currently logged on
user's name in "HttpContext.Current.User.Identity.Name" which has
been mapped to be stored in "GeneralInfo.logon_name" in the
Commerce Profile Database. The userIdKey field in this section tells
the UpmMembershipProvider which field should be searched to get the
Commerce Server User Object instance using the value provided by the
ASP.Net current user context:
(HttpContext.Current.User.Identity.Name). The value of this field
should therefore be the same as the field specified in the Membership
section, "GeneralInfo.logon_name".
userIdTarget: The value of this field specifies which field in the
Profile Identifies the user and will dictate what the value of
"CommerceContext.Current.UserId" will be. The default value is
"GeneralInfo.user_id", but another field can be specified to
uniquely identify the user.

5. Using the ASP.Net Login and CreateUserWizard controls

Now that we have configured the web site to use the UpmMembership
provider, we can use the ASP.Net login controls to authenticate and
register users against the Commerce Server database.
These controls implement login, password management and registration
code for you.

5.1 Login and password management controls.

Simply dragging these controls on the page will add login and password
management functionality to your application which will be implemented
against the Commerce Server System.

5.2 CreateUserWizard Control.

Should you wish to capture additional information during the
registration process, the CreateUserWizard Control templates can be
modified to contain additional fields. See MSDN documentation on how
to do this.

In order to ensure the Commerce Server profile gets updated with this
information, some additional code will be required. In this code
sample, a First and Last name field has been added to the
CreateUserWizard template.

In order to update the Commerce Profile with this data, I did the
following:

Attach an event handler to the ContinueButtonClick event which fires
after the membership provider has created the user.

In the event handler, the CommerceContext.Current.UserProfile should be
the newly created user profile. If not, get the user profile like
this:

Profile prof =
CommerceContext.Current.ProfileSystem.GetProfile("logon_name",
CreateUserWizard1.UserName, "UserObject");

To access the controls for the First and Last name:

TextBox tb =
(TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstName");
if (tb != null)
prof.Properties["GeneralInfo.first_name"].Value = tb.Text;

Update the profile database by calling: prof.Update();


Apologies for the formatting. I hope you find this useful.

Vinayak Tadas[MSFT]

2006-06-19, 2:48 pm

Thanks for posting this!
Thanks
Vinayak Tadas
Microsoft
http://blogs.msdn.com/vinayakt

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2002 Microsoft Corporation. All rights
reserved.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Get Secure! For more info visit http://www.microsoft.com/security. Please
reply to the newsgroups only


--------------------
From: "Amy" <amy.dudley@gmail.com>
Newsgroups: microsoft.public.commerceserver.general
Subject: How to implement the UpmMembershipProvider in CS 2007
Date: 18 Jun 2006 00:05:07 -0700
Organization: http://groups.google.com
Lines: 179
Message-ID: <1150614307.926415.285910@i40g2000cwc.googlegroups.com>
NNTP-Posting-Host: 198.54.202.210
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1150614311 30849 127.0.0.1 (18 Jun 2006
07:05:11 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 18 Jun 2006 07:05:11 +0000 (UTC)
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1;
NET CLR 1.1.4322; .NET CLR 2.0.50727; WinFX RunTime
3.0.50727),gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 rba-cache3 (NetCache NetApp/5.6.2R1D2), 1.1 rba-cache2
(NetCache NetApp/6.0.3D3)
Complaints-To: groups-abuse@google.com
Injection-Info: i40g2000cwc.googlegroups.com; posting-host=198.54.202.210;
posting- account=8Fh5yw0AAACOv04BHcz2n60DvMO1Zb4b

Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTFEEDS01.phx.gbl!msrtrans!m
srn-in!newshub.sdsu.edu!postnews.google.com!i40g2000cwc.googlegroups.com!not
-for-mail
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.commerceserver.general:17906
X-Tomcat-NG: microsoft.public.commerceserver.general

The UpmMembership Provider extends the Membership framework offered by
ASP.Net to accommodate the use of the ASP.Net Login Controls and
authenticate against Commerce Server Profiles and according to Commerce
Server 2007 documentation is the recommended means of authentication
and password management.

1. Configuring the Commerce Server UserObject Profile

The Commerce Server UserObject profile must have at least the following
fields defined:

GeneralInfo.user_id: This field usually pre-configured if a sample or
starter site has been unpupped. It is of type GUID and must be
configured to be a unique key. This field is used to uniquely
identify the user.
GeneralInfo.security_password: This field stores the user password
GeneralInfo.email_address: This field stores the user email address.

Note: By default, the UpmMembership provider uses the
GeneralInfo.email_address as the logon name field. In this example, I
have created a new profile field called "GeneralInfo.logon_name" in
the UserObject Profile definition in Commerce Server and will implement
the UpmMembership provider to use this field as the logon name as
opposed to the GeneralInfo.emal_address field.

2. Configure the application to use Forms Authentication

In the web.config file in the <system.web> section, modify the
<authentication> tag as follows:
<authentication mode="Forms">
<forms name=".yourappname" loginUrl="yourloginurl.aspx" />
</authentication>

This will configure the Commerce Application to use forms
authentication.

3. Configuring the site to use the UpmMembership Provider

In the web.config file, add or update the <system.web><Membership>
section as follows:
<membership defaultProvider="UpmMembershipProvider">
<providers>
<clear />
<add applicationName="YourAppName"
enablePasswordRetrieval="false" enablePasswordReset="true"
logonNameProperty="GeneralInfo.logon_name"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="true" enableCreateDate="true"
enableEmailAddress="true"
enableLastLoginDate="true" profileDefinition="UserObject"

passwordFormat="Hashed" name="UpmMembershipProvider"
type="Microsoft.CommerceServer.Runtime.Profiles.UpmMembershipProvider"
/>
</providers>
</membership>

Items worthy of note here are:
defaultProvider attribute: This is the name of the provider that will
be used by default.
logonPropertyName: If not specified the provider will use
"GeneralInfo.email_address " by default. In this case a
"GeneralInfo.logon_name" field has been defined in the user object
profile and will be used to store the logon name.
name: This attribute identifies the provider. The value of this
attribute corresponds to the value of the "defaultProvider"
attribute specified in the "Membership" node.
type: This is the type name of the membership provider and in the case
of CS 2007 should be:
"Microsoft.CommerceServer.Runtime.Profiles.UpmMembershipProvider."

Note: These attributes are XML and are therefore case-sensitive.

There are various other attributes which can be configure here, the use
of which are defined in Membership Documentation for ASP.Net as well as
the Membership Documentation for Commerce Server.

4. Configuring the Commerce Server Profiles section

This section contains settings which configure the functionality of
profiles and catalogsets. This article will refer only to those
attributes applicable to the UpmMembershipProvider.
The <userProfile> node resides in the <CommerceServer><profiles> node
in the web.config

<userProfile profileDefinition="UserObject"
userIdProperty="GeneralInfo.user_id"
organizationIdProperty="AccountInfo.org_id"
catalogSetIdProperty="AccountInfo.user_catalog_set"

userIdSource = "ASP.Net"
userIdKey="GeneralInfo.logon_name"
userIdTarget="GeneralInfo.user_id"
/>

A brief description of these attributes and what they do follows:

profileDefinition: Refers to the Profile Definition defined in
Commerce Server which contains user profiles. This would usually be
"UserObject" but can be customized to use an alternative profile
definition.
userIdProperty: This attribute identifies the field which is a member
of the aforementioned profileDefinition which uniquely identifies the
user. By default this field is "GeneralInfo.user_id"
userIdSource: There are two possible values for this field, "UPM"
and "ASP.Net". When implementing the Membership provider, this
value should be configured to "ASP.Net" which is the default value.
userIdKey: In the Membership configuration section described in the
previous section, we configured the "logonPropertyName" field's
value to "GeneralInfo.logon_name". This property tells the
UpmMembershipProvider to store the logon name in this field in the
profile DB. The ASP.Net framework stores the currently logged on
user's name in "HttpContext.Current.User.Identity.Name" which has
been mapped to be stored in "GeneralInfo.logon_name" in the
Commerce Profile Database. The userIdKey field in this section tells
the UpmMembershipProvider which field should be searched to get the
Commerce Server User Object instance using the value provided by the
ASP.Net current user context:
(HttpContext.Current.User.Identity.Name). The value of this field
should therefore be the same as the field specified in the Membership
section, "GeneralInfo.logon_name".
userIdTarget: The value of this field specifies which field in the
Profile Identifies the user and will dictate what the value of
"CommerceContext.Current.UserId" will be. The default value is
"GeneralInfo.user_id", but another field can be specified to
uniquely identify the user.

5. Using the ASP.Net Login and CreateUserWizard controls

Now that we have configured the web site to use the UpmMembership
provider, we can use the ASP.Net login controls to authenticate and
register users against the Commerce Server database.
These controls implement login, password management and registration
code for you.

5.1 Login and password management controls.

Simply dragging these controls on the page will add login and password
management functionality to your application which will be implemented
against the Commerce Server System.

5.2 CreateUserWizard Control.

Should you wish to capture additional information during the
registration process, the CreateUserWizard Control templates can be
modified to contain additional fields. See MSDN documentation on how
to do this.

In order to ensure the Commerce Server profile gets updated with this
information, some additional code will be required. In this code
sample, a First and Last name field has been added to the
CreateUserWizard template.

In order to update the Commerce Profile with this data, I did the
following:

Attach an event handler to the ContinueButtonClick event which fires
after the membership provider has created the user.

In the event handler, the CommerceContext.Current.UserProfile should be
the newly created user profile. If not, get the user profile like
this:

Profile prof =
CommerceContext.Current.ProfileSystem.GetProfile("logon_name",
CreateUserWizard1.UserName, "UserObject");

To access the controls for the First and Last name:

TextBox tb =
(TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindContr
ol("FirstName");
if (tb != null)
prof.Properties["GeneralInfo.first_name"].Value = tb.Text;

Update the profile database by calling: prof.Update();


Apologies for the formatting. I hope you find this useful.


Vinayak Tadas[MSFT]

2006-06-19, 7:19 pm

Thanks for posting this!
Thanks
Vinayak Tadas
Microsoft
http://blogs.msdn.com/vinayakt

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2002 Microsoft Corporation. All rights
reserved.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Get Secure! For more info visit http://www.microsoft.com/security. Please
reply to the newsgroups only


--------------------
From: "Amy" <amy.dudley@gmail.com>
Newsgroups: microsoft.public.commerceserver.general
Subject: How to implement the UpmMembershipProvider in CS 2007
Date: 18 Jun 2006 00:05:07 -0700
Organization: http://groups.google.com
Lines: 179
Message-ID: <1150614307.926415.285910@i40g2000cwc.googlegroups.com>
NNTP-Posting-Host: 198.54.202.210
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1150614311 30849 127.0.0.1 (18 Jun 2006
07:05:11 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 18 Jun 2006 07:05:11 +0000 (UTC)
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1;
.NET CLR 1.1.4322; .NET CLR 2.0.50727; WinFX RunTime
3.0.50727),gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 rba-cache3 (NetCache NetApp/5.6.2R1D2), 1.1 rba-cache2
(NetCache NetApp/6.0.3D3)
Complaints-To: groups-abuse@google.com
Injection-Info: i40g2000cwc.googlegroups.com; posting-host=198.54.202.210;
posting- account=8Fh5yw0AAACOv04BHcz2n60DvMO1Zb4b

Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTFEEDS01.phx.gbl!msrtrans!m
srn-in!newshub.sdsu.edu!postnews.google.com!i40g2000cwc.googlegroups.com!not
-for-mail
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.commerceserver.general:17906
X-Tomcat-NG: microsoft.public.commerceserver.general

The UpmMembership Provider extends the Membership framework offered by
ASP.Net to accommodate the use of the ASP.Net Login Controls and
authenticate against Commerce Server Profiles and according to Commerce
Server 2007 documentation is the recommended means of authentication
and password management.

1. Configuring the Commerce Server UserObject Profile

The Commerce Server UserObject profile must have at least the following
fields defined:

GeneralInfo.user_id: This field usually pre-configured if a sample or
starter site has been unpupped. It is of type GUID and must be
configured to be a unique key. This field is used to uniquely
identify the user.
GeneralInfo.security_password: This field stores the user password
GeneralInfo.email_address: This field stores the user email address.

Note: By default, the UpmMembership provider uses the
GeneralInfo.email_address as the logon name field. In this example, I
have created a new profile field called "GeneralInfo.logon_name" in
the UserObject Profile definition in Commerce Server and will implement
the UpmMembership provider to use this field as the logon name as
opposed to the GeneralInfo.emal_address field.

2. Configure the application to use Forms Authentication

In the web.config file in the <system.web> section, modify the
<authentication> tag as follows:
<authentication mode="Forms">
<forms name=".yourappname" loginUrl="yourloginurl.aspx" />
</authentication>

This will configure the Commerce Application to use forms
authentication.

3. Configuring the site to use the UpmMembership Provider

In the web.config file, add or update the <system.web><Membership>
section as follows:
<membership defaultProvider="UpmMembershipProvider">
<providers>
<clear />
<add applicationName="YourAppName"
enablePasswordRetrieval="false" enablePasswordReset="true"
logonNameProperty="GeneralInfo.logon_name"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="true" enableCreateDate="true"
enableEmailAddress="true"
enableLastLoginDate="true" profileDefinition="UserObject"

passwordFormat="Hashed" name="UpmMembershipProvider"
type="Microsoft.CommerceServer.Runtime.Profiles.UpmMembershipProvider"
/>
</providers>
</membership>

Items worthy of note here are:
defaultProvider attribute: This is the name of the provider that will
be used by default.
logonPropertyName: If not specified the provider will use
"GeneralInfo.email_address " by default. In this case a
"GeneralInfo.logon_name" field has been defined in the user object
profile and will be used to store the logon name.
name: This attribute identifies the provider. The value of this
attribute corresponds to the value of the "defaultProvider"
attribute specified in the "Membership" node.
type: This is the type name of the membership provider and in the case
of CS 2007 should be:
"Microsoft.CommerceServer.Runtime.Profiles.UpmMembershipProvider."

Note: These attributes are XML and are therefore case-sensitive.

There are various other attributes which can be configure here, the use
of which are defined in Membership Documentation for ASP.Net as well as
the Membership Documentation for Commerce Server.

4. Configuring the Commerce Server Profiles section

This section contains settings which configure the functionality of
profiles and catalogsets. This article will refer only to those
attributes applicable to the UpmMembershipProvider.
The <userProfile> node resides in the <CommerceServer><profiles> node
in the web.config

<userProfile profileDefinition="UserObject"
userIdProperty="GeneralInfo.user_id"
organizationIdProperty="AccountInfo.org_id"
catalogSetIdProperty="AccountInfo.user_catalog_set"

userIdSource = "ASP.Net"
userIdKey="GeneralInfo.logon_name"
userIdTarget="GeneralInfo.user_id"
/>

A brief description of these attributes and what they do follows:

profileDefinition: Refers to the Profile Definition defined in
Commerce Server which contains user profiles. This would usually be
"UserObject" but can be customized to use an alternative profile
definition.
userIdProperty: This attribute identifies the field which is a member
of the aforementioned profileDefinition which uniquely identifies the
user. By default this field is "GeneralInfo.user_id"
userIdSource: There are two possible values for this field, "UPM"
and "ASP.Net". When implementing the Membership provider, this
value should be configured to "ASP.Net" which is the default value.
userIdKey: In the Membership configuration section described in the
previous section, we configured the "logonPropertyName" field's
value to "GeneralInfo.logon_name". This property tells the
UpmMembershipProvider to store the logon name in this field in the
profile DB. The ASP.Net framework stores the currently logged on
user's name in "HttpContext.Current.User.Identity.Name" which has
been mapped to be stored in "GeneralInfo.logon_name" in the
Commerce Profile Database. The userIdKey field in this section tells
the UpmMembershipProvider which field should be searched to get the
Commerce Server User Object instance using the value provided by the
ASP.Net current user context:
(HttpContext.Current.User.Identity.Name). The value of this field
should therefore be the same as the field specified in the Membership
section, "GeneralInfo.logon_name".
userIdTarget: The value of this field specifies which field in the
Profile Identifies the user and will dictate what the value of
"CommerceContext.Current.UserId" will be. The default value is
"GeneralInfo.user_id", but another field can be specified to
uniquely identify the user.

5. Using the ASP.Net Login and CreateUserWizard controls

Now that we have configured the web site to use the UpmMembership
provider, we can use the ASP.Net login controls to authenticate and
register users against the Commerce Server database.
These controls implement login, password management and registration
code for you.

5.1 Login and password management controls.

Simply dragging these controls on the page will add login and password
management functionality to your application which will be implemented
against the Commerce Server System.

5.2 CreateUserWizard Control.

Should you wish to capture additional information during the
registration process, the CreateUserWizard Control templates can be
modified to contain additional fields. See MSDN documentation on how
to do this.

In order to ensure the Commerce Server profile gets updated with this
information, some additional code will be required. In this code
sample, a First and Last name field has been added to the
CreateUserWizard template.

In order to update the Commerce Profile with this data, I did the
following:

Attach an event handler to the ContinueButtonClick event which fires
after the membership provider has created the user.

In the event handler, the CommerceContext.Current.UserProfile should be
the newly created user profile. If not, get the user profile like
this:

Profile prof =
CommerceContext.Current.ProfileSystem.GetProfile("logon_name",
CreateUserWizard1.UserName, "UserObject");

To access the controls for the First and Last name:

TextBox tb =
(TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindContr
ol("FirstName");
if (tb != null)
prof.Properties["GeneralInfo.first_name"].Value = tb.Text;

Update the profile database by calling: prof.Update();


Apologies for the formatting. I hope you find this useful.


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com