In the previous example, if you want to use profile, you can use it in two states: use it after login, and use profile anonymously without logon. However, in some e-commerce applications, users often use shopping cart in the anonymous status, but login or registration is required during the checkout. In this case, the data added to the shopping cart in the anonymous State needs to be moved to the shopping cart after the user logs on. To achieve this effect, you must writeCodeTo achieve this:
In this example, the key is to implement the migrateanonymous event in the profilemodule class. This event is triggered when an anonymous user logs on and the profile contains data. Unlike other events, this event is handledProgramIt must be defined in the Global. asax file.
The procedure is as follows:
Add a global. asax file to the project and copy the following code to the file.
Void Profile_migrateanonymous ( Object Sender, profilemigrateeventargs PE)
{
// Obtain the user's data in the anonymous status
Profilecommon PC = Profile. getprofile (PE. anonymousid );
// Check whether data is added to the shopping cart
If (PC. Cart. Count ! = 0 )
{
// If data exists, add the added items in the anonymous status to the shopping cart after login.
// Note: profile. Cart stores the data after login.
// PC. cart is the data that the user adds anonymously.
Profile. cart = PC. cart;
}
// Delete records of anonymous users in the aspnet_users table
Membership. deleteuser (PE. anonymousid );
// Delete anonymous user profile data
Profilemanager. deleteprofile (PE. anonymousid );
// Delete an anonymous user ID
Anonymousidentificationmodule. clearanonymousidentifier ();
}
OK. That's simple ~~