Profile customization for ASP. NET users -- migration from anonymous users to registered users

Source: Internet
Author: User

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 ~~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.