asp.net2.0 Learning 7--Personalized User Configuration

Source: Internet
Author: User
Tags anonymous config datetime empty connectionstrings
asp.net

Personalized User Configuration

First, Introduction

To provide users with customized appearance, content, layout, when users visit again, users can also see their original settings.

Second, the three major steps of personalization

1. Identify user identity

To establish a mechanism for authenticating user identities

Create a mechanism to identify user needs

Creating a mechanism for managing users

2. Provide personalized service

Provide different services for registration and anonymous users

3. Storing user information

You can save information about the user to facilitate the next use, including user login information

Third, realize the three main functions of personalized service

1. Personalized User Configuration

2. Web Part

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 User Configuration information in profile properties

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 ()

{

To get data from the profile property 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 the value is not fetched, the display is empty, otherwise the obtained value is displayed

if (time. Year = = 1)

{

Lablastsubmit.text = "Empty";

}

Else

{

Lablastsubmit.text = time. ToString ();

}

}

V. Implement personalized User Configuration for registered users

Web.config configuration

<connectionStrings>

<add name= "NorthwindConnectionString" connectionstring= "Data source=localhost;initial Catalog=Northwind;I ntegrated 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>

code example: 13-2

Vi. Conversion of anonymous users to registered users

Settings in Global.asax

void Profile_migrateanonymous (Object sender, Profilemigrateeventargs PE)

{

Get profile object for anonymous user

ProfileCommon anonprofile = Profile.getprofile (PE. ANONYMOUSID);

If the total price is not 0 (indicating that the anonymous user made the selection), the profile of the anonymous user is stored

if (anonProfile.ShoppingCart.Total!= 0)

{

Profile.shoppingcart = Anonprofile.shoppingcart;

}

Delete user data from an anonymous user (from the Aspnet_users table)

Membership.deleteuser (PE. ANONYMOUSID);

Delete profle data from an anonymous user (from the Aspnet_profile table)

Profilemanager.deleteprofile (PE. ANONYMOUSID);

To delete an anonymous user identity

Anonymousidentificationmodule.clearanonymousidentifier ();

}

Sample codes: Code 13-3

Vii. Deleting personalized information

Remove personalization information for anonymous users

Profilemanager.deleteprofile (Context.Request.AnonymousID)

Remove personalized information for registered users

Profilemanager.deleteprofile (User.Identity.Name)



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.