asp.net2.0 Security (2)--User personalization (2)--reprint from the car teacher

Source: Internet
Author: User
Tags guid identifier

We can read the user's age and other information in the way of profile.age, but sometimes we want to query display all user's information, but ASP. NET does not provide the function of querying all user information, we can only query the profile information of the existing users one by one.

First step: Setting up the configuration file

Step two: Get all the Users

Membershipusercollection users = Membership.getallusers ();

The GetAllUsers () method of the membership class is used here, which has already been described in "User and role management" and is no longer mentioned.

The third step: Compiling Calendar Users collection, take each user's profile

foreach (MembershipUser singleuser in Users)

{

ProfileCommon userprofile = Profile.getprofile (singleuser.username);

Response.Write (Userprofile.name);

Response.Write (Userprofile.age);

Response.Write (Userprofile.school);

}

Read the profile of an anonymous user

Anonymous users also have profile? The answer is yes. As mentioned earlier, asp.net2.0 joins an anonymous tracking mechanism that can produce a unique GUID identifier attached to the request of an unauthenticated Web page.

The default "anonymous identification" is disabled, so if you want your site to recognize anonymous users, you need to configure the following in the Web. config file:

<system.web>

<anonymousidentification enabled= "true"/>

</system.web>

This can be used when the setup is complete. Request.anonymousid Remove the user's GUID.

Using anonymous user profile for the field:

1) In the past to do shopping sites, we put the shopping cart in the session, but the session has a certain expiration policy, generally 20 minutes. If we take a half-hour stroll to checkout, the shopping cart data is best preserved through profile.

2) Someone shopping site does not like to login and then buy, and when wandering around to find a good thing, here to login to buy the words will make users feel a little annoyed, especially in the network speed is relatively slow situation. In this case, you can use anonymous identity to record what the user buys, and then let the user enter the account password to checkout.

There are two key points to using anonymous profiles:

1) Set the Enable property of the anonymousidentification to True

2) also set the corresponding anonymously saved Profile field property to Allowanonymous= "true"

To store information using anonymous profiles:

First step: Set the Enable property of anonymousidentification to True

<anonymousidentification enabled= "true" cookieless= "UseCookies" ></anonymousIdentification>

Step two: Set the foreground color and background color two properties to allowanonymous= "true" in the Web. config file

<profile>

<properties>

<add name= "name" type= "System.String" ></add>

<add name= "Age" type= "System.Int32" ></add>

<add name= "School" type= "System.String" ></add>

<group name= "Color" >

<add name= "ForeColor" type= "System.Drawing.Color" serializeas= "Binary" allowanonymous= "true" ></add>

<add name= "BackColor" type= "System.Drawing.Color" serializeas= "Binary" allowanonymous= "true" ></add>

</group>

</properties>

<profile>

Step Three:

Set the foreground and background colors for anonymous users

Profile.color.backcolor = Color.fromname (Listback.text);

Profile.color.forecolor = Color.fromname (Listfore.text);

Label1.forecolor = Profile.color.forecolor;

Label1.backcolor = Profile.color.backcolor;

Fourth step: View the contents of the Aspnet_profile table and find that the colors are stored in the table.

Migration of anonymous profiles to logged-in users (migration)

First step: Above

Step Two: Above

Step Three: Above

Fourth Step: Add the following code to the Global.asax of the website:

void Profile_migrateanonymous (object sender, Profilemigrateeventargs args)

{

Get the ID of the anonymous user

ProfileCommon anonyprofile = Profile.getprofile (args. ANONYMOUSID);

if ((AnonyProfile.color.backcolor! = null) && (AnonyProfile.color.forecolor! = null))

{

Profile.color.forecolor = AnonyProfile.color.forecolor;

Profile.color.backcolor = AnonyProfile.color.backcolor;

Profile.save ();

}

To delete the profile of an anonymous user

Profilemanager.deleteprofile (args. ANONYMOUSID);

Clear cookies or identity information for anonymous users

Anonymousidentificationmodule.clearanonymousidentifier ();

}

A profile_migrateanonymous event is raised when a user logs on to migrate an anonymous user to a user's profile

(Che Yanlu)

Collected in 2007-07-03

asp.net2.0 Security (2)--User personalization (2)--reprint from the car teacher

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.