creating user profile in a loop
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Microsoft Commerce Server > Commerce Server General > creating user profile in a loop




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    creating user profile in a loop  
JC


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-30-06 12:49 AM

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 wel
l.
What should I do in order to assign Address object to the latest created
profile?

Thanks for any help






[ Post a follow-up to this message ]



    Re: creating user profile in a loop  
Colin Bowern


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-30-06 06: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
>







[ Post a follow-up to this message ]



    Re: creating user profile in a loop  
JC


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-01-06 06: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);	Commer
ceContext.Current.AuthenticationInfo.SetAuthTicket("",true);
Session.Abandon();
}


"Colin Bowern" wrote:

> JC,
>
> What version of Commerce Server are you using?  Is this in a web or consol
e
> 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... 
>
>
>





[ Post a follow-up to this message ]



    Re: creating user profile in a loop  
Colin Bowern


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-01-06 06: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:
> 





[ Post a follow-up to this message ]



    Re: creating user profile in a loop  
JC


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-01-06 06: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... 





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 02:00 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register