Commerce Server General - creating user profile in a loop

This is Interesting: Free IT Magazines  
Home > Archive > Commerce Server General > October 2006 > creating user profile in a loop





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 creating user profile in a loop
JC

2006-09-29, 7:49 pm

Hi,

I had to create a procedure, which loops thru list of users and create a
profile for each of them. Also I am assigning addresses to those users.
Everything goes fine and profile gets created with unique GUID but when I am
trying to assign address the Address object gets created for the first
created profile – it creates an address with g_id = first created GUID.
I also mentioned that UserObject..CurrentUser.UserID doesn’t change as well.
What should I do in order to assign Address object to the latest created
profile?

Thanks for any help

Colin Bowern

2006-09-30, 1:36 am

JC,

What version of Commerce Server are you using? Is this in a web or console
application context? Can you post a sample snippet of code?

Cheers,
Colin

"JC" <JC@discussions.microsoft.com> wrote in message
news:15696716-096B-496F-9EA4-BB9D4CD7B957@microsoft.com...
> Hi,
>
> I had to create a procedure, which loops thru list of users and create a
> profile for each of them. Also I am assigning addresses to those users.
> Everything goes fine and profile gets created with unique GUID but when I
> am
> trying to assign address the Address object gets created for the first
> created profile - it creates an address with g_id = first created GUID.
> I also mentioned that UserObject..CurrentUser.UserID doesn't change as
> well.
> What should I do in order to assign Address object to the latest created
> profile?
>
> Thanks for any help
>



JC

2006-10-01, 1:26 am

Colin,
Thank you for your response.
This is MSIB web app, Commerce 2002 and Content Management Server 2002.
Below is the sample of my code:

while (drUsers.Read())
{
// Create UserObject profile.
UserObject userProfile = UserObject.CreateUserProfile (LogonName);

// Set profile properties and save profile.
SetProfileProperties (userProfile, LogonName, Password, FirstNAme, LastName);
userProfile.Save();

// Automatically authenticate user and move the anonymous information to the
// // registered profile!!

MicrosoftInternetBusinessSite.DefaultAuthProvider.Login (LogonName,
Password);
SiteAuthPolicyValidator.MoveAnonymousInfoToAuthenticatedUser();

while (drAddresses.Read())
{
Address userAddress;
// Set profile properties and update profile.

SetAddressProperties (par1, par2, par3 ………);
userAddress.Update();
UserObject.CurrentUser.PreferredAddress = userAddress;
UserObject.CurrentUser.Save();
}

MicrosoftInternetBusinessSite.DefaultAuthProvider.Logout();
CommerceContext.Current.AuthenticationInfo.SetProfileTicket("",true); CommerceContext.Current.AuthenticationInfo.SetAuthTicket("",true);
Session.Abandon();
}


"Colin Bowern" wrote:

> JC,
>
> What version of Commerce Server are you using? Is this in a web or console
> application context? Can you post a sample snippet of code?
>
> Cheers,
> Colin
>
> "JC" <JC@discussions.microsoft.com> wrote in message
> news:15696716-096B-496F-9EA4-BB9D4CD7B957@microsoft.com...
>
>
>

Colin Bowern

2006-10-01, 1:26 am

JC,

From first glance it appears that the UserObject.CurrentUser isn't being
updated as I'm sure you've identified. I don't have a copy of MSIB
installed at the moment as I'm knee deep in CS2007 work, but if you used
Reflector to look under the covers I would bet that CurrentUser is cached
until a new web request occurs.

The reason I say this is that I had to force CommerceContext to update for
similar purposes in our CS2002 release. I wanted to log the user in and
then update a few variables without waiting for the next web request.
Pseudo-code wise it looked something similar to the following:

CommerceContext CSContext = CommerceContext.Current;
....
Profile profile = RetrieveUserProfile(...);
....
CSContext.AuthenticationInfo.SetProfileTicket(profile.Id, true);
....
CSContext.UserID = profile.Id; <-- This was the force update
CSContext.UserProfile = profile; <-- This was the force update

Hope that helps!
Colin


"JC" <JC@discussions.microsoft.com> wrote in message
news:1D55C68E-F89A-4DD2-A233-88915F29BFC8@microsoft.com...[vbcol=seagreen]
> Colin,
> Thank you for your response.
> This is MSIB web app, Commerce 2002 and Content Management Server 2002.
> Below is the sample of my code:
>
> while (drUsers.Read())
> {
> // Create UserObject profile.
> UserObject userProfile = UserObject.CreateUserProfile (LogonName);
>
> // Set profile properties and save profile.
> SetProfileProperties (userProfile, LogonName, Password, FirstNAme,
> LastName);
> userProfile.Save();
>
> // Automatically authenticate user and move the anonymous information to
> the
> // // registered profile!!
>
> MicrosoftInternetBusinessSite.DefaultAuthProvider.Login (LogonName,
> Password);
> SiteAuthPolicyValidator.MoveAnonymousInfoToAuthenticatedUser();
>
> while (drAddresses.Read())
> {
> Address userAddress;
> // Set profile properties and update profile.
>
> SetAddressProperties (par1, par2, par3 ………);
> userAddress.Update();
> UserObject.CurrentUser.PreferredAddress = userAddress;
> UserObject.CurrentUser.Save();
> }
>
> MicrosoftInternetBusinessSite.DefaultAuthProvider.Logout();
> CommerceContext.Current.AuthenticationInfo.SetProfileTicket("",true);
> CommerceContext.Current.AuthenticationInfo.SetAuthTicket("",true);
> Session.Abandon();
> }
>
>
> "Colin Bowern" wrote:
>
JC

2006-10-01, 1:26 am

Colin,

Thank you for your very detailed response and the reflector advice was
priceless.

Thank you.


"Colin Bowern" wrote:
[vbcol=seagreen]
> JC,
>
> From first glance it appears that the UserObject.CurrentUser isn't being
> updated as I'm sure you've identified. I don't have a copy of MSIB
> installed at the moment as I'm knee deep in CS2007 work, but if you used
> Reflector to look under the covers I would bet that CurrentUser is cached
> until a new web request occurs.
>
> The reason I say this is that I had to force CommerceContext to update for
> similar purposes in our CS2002 release. I wanted to log the user in and
> then update a few variables without waiting for the next web request.
> Pseudo-code wise it looked something similar to the following:
>
> CommerceContext CSContext = CommerceContext.Current;
> ...
> Profile profile = RetrieveUserProfile(...);
> ...
> CSContext.AuthenticationInfo.SetProfileTicket(profile.Id, true);
> ...
> CSContext.UserID = profile.Id; <-- This was the force update
> CSContext.UserProfile = profile; <-- This was the force update
>
> Hope that helps!
> Colin
>
>
> "JC" <JC@discussions.microsoft.com> wrote in message
> news:1D55C68E-F89A-4DD2-A233-88915F29BFC8@microsoft.com...
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com