ASP. NET2.0-personalized user configuration

Source: Internet
Author: User

I. Introduction

It provides users with custom appearances, contents, and la S. When users access the page again, they can see their original settings.

 

2. Three Steps of personalization

1. Identify a user

To establish a mechanism to authenticate user identities

Create a mechanism to identify user needs

Create a user management mechanism

2. provide personalized services

Provide different services for registered and anonymous users

3. Store user information

You can save user-related information to facilitate next use, including user login information.

 

3. implement three features of personalized services

1. personalized user configuration

2. WEB parts

3. Member and role management

 

Iv. personalized settings for anonymous users

Web. config Configuration

<AnonymousIdentification enabled = "true"/>

<Profile>

<Properties>

<Add name = "Name" allowAnonymous = "true"/>

<Add name = "LastSubmit" type = "System. DateTime" allowAnonymous = "true"/>

<Group name = "Address">

<Add name = "City" allowAnonymous = "true"/>

<Add name = "PostalCode" allowAnonymous = "true"/>

</Group>

</Properties>

</Profile>

 

Code:

Protected void Page_Load (object sender, EventArgs e)

{

If (! Page. IsPostBack)

{

// Display User Configuration Information

DisplayProfileInfo ();

}

}

Protected void btnSubmit_Click (object sender, EventArgs e)

{

// Save the user configuration information to the Profile attribute

Profile. Name = txtName. Text;

Profile. Address. City = txtCity. Text;

Profile. Address. PostalCode = txtPostalCode. Text;

Profile. LastSubmit = DateTime. Now;

// Display User Configuration Information

DisplayProfileInfo ();

}

Private void DisplayProfileInfo ()

{

// Obtain data from the Profile attribute and assign it to the server control

TxtName. Text = Profile. Name;

TxtCity. Text = Profile. Address. City;

TxtPostalCode. Text = Profile. Address. PostalCode;

DateTime time = Profile. LastSubmit;

// If no value is available, the system displays NULL; otherwise, the obtained value is displayed.

If (time. Year = 1)

{

LabLastSubmit. Text = "null ";

}

Else

{

LabLastSubmit. Text = time. ToString ();

}

}

 

5. personalized user configuration for registered users

Web. config Configuration

 

<ConnectionStrings>

<Add name = "NorthwindConnectionString" connectionString = "Data Source = localhost; Initial Catalog = Northwind; Integrated Security = True"

ProviderName = "System. Data. SqlClient"/>

</ConnectionStrings>

<System. web>

<Profile>

<Properties>

<Add name = "ShoppingCart" type = "ShoppingCart" serializeAs = "Binary"/>

</Properties>

</Profile>

<Authorization>

<Deny users = "? "/>

</Authorization>

<Authentication mode = "Forms">

<Forms loginUrl = "Login. aspx"> </forms>

</Authentication>

 

 

6. Processing of converting anonymous users into registered users

Settings in Global. asax

Void Profile_MigrateAnonymous (Object sender, ProfileMigrateEventArgs pe)

{

// Obtain the Profile object of an anonymous user

ProfileCommon anonProfile = Profile. GetProfile (pe. AnonymousID );

// If the total price is not 0 (indicating that anonymous users have selected), store the Profile of anonymous users.

If (anonProfile. ShoppingCart. Total! = 0)

{

Profile. ShoppingCart = anonProfile. ShoppingCart;

}

// Delete anonymous user data (from the aspnet_Users table)

Membership. DeleteUser (pe. AnonymousID );

// Delete the Profle data of anonymous users (from the aspnet_Profile table)

ProfileManager. DeleteProfile (pe. AnonymousID );

// Delete the anonymous user ID

AnonymousIdentificationModule. ClearAnonymousIdentifier ();

}

 

7. Delete personalized information

Delete personalized information of Anonymous Users

ProfileManager. DeleteProfile (Context. Request. AnonymousID)

Delete personalized information of registered users

ProfileManager. DeleteProfile (User. Identity. Name)

 

 

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.