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

Source: Internet
Author: User

In the membership table can store some basic information of users, but sometimes, we need to record the user information far more than the membership table provides these, such as QQ, MSN, home address, contact telephone and so on. How do you record these user information in a database? In asp.net2.0, we provide the function ――profile of personality setting. Here's a look at some of the features of profile:

1) Profile stores individual user data, including anonymous information, based on each user.

2) profile can be defined in Web. config and takes effect immediately without having to manually expand the database fields.

3) profile can store any data type, including simple data types and custom complex data types.

How does the profile implement the above functions?

Asp.net2.0 verifies the identity of each logged-in user, generates a GUID for the anonymous request user, which is a unique identifier that uniquely identifies the user, so that the user for each request is invisible and the identity of each individual is not disturbed. How does ASP. Expand the user's other information freely, based on the non-expansion field? Everyone opens the Aspnet_profile table in the SQLSERVER2005 database to see that there are two fields PropertyNames and propertyvaluesstring. The Propertyvaluesstring field contains all the information you add to the user profile, which is stored as a text stream, and the PropertyNames field describes how to parse the contents of the Propertyvaluesstring field. It is also present in the form of a text stream. This allows you to customize any field and write the information in the table.

Let's look at how to implement the read and write of the profile file:

1. Expand the "real name", "Age" and "school" three customized user information

First step: Define the settings file

<system.web>

<profile>

<properties>

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

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

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

</properties>

</profile>

</system.web>

Step two: Using Profile in VS2005

Write profile to Database

if (User.Identity.IsAuthenticated)

{

Profile.name = txtName.Text;

Profile.age = Convert.ToInt32 (Txtage.text);

Profile.school = Txtschool.text;

}

To read the profile from the database to the page

if (User.Identity.IsAuthenticated)

{

txtName.Text = Profile.name;

Txtage.text = Profile.age.ToString ();

Txtschool.text = Profile.school;

}

Step three: View the Aspnet_profile table and you will find the information that you have added to your customizations.

The default personalization information is stored in the database under the App_date folder, and the following provider settings are required if the personalization information is stored in the specified database:

<profile>

<providers>
<remove name= "AspNetSqlProfileProvider"/>
<clear/>
<add name= "AspNetSqlProfileProvider" connectionstringname= "conn" type= "System.Web.Profile.SqlProfileProvider" description= "Storing profile data"/>
<!--<add name= "Textfileprofileprovider" type= "Customproviders.textfileprofileprovider, CustomProviders" description= "Text file profile provider"/>-->
</providers>

<properties>

......

</<properties>

</profile>

2, the date of birth and blood type are added to the existing custom data, the date of birth and blood type can be set as a group

First step: Define the settings file

<system.web>

<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= "Other" >

<add name= "Birthday" type= "System.DateTime" ></add>

<add name= "Blood" type= "String" ></add>

</group>

</properties>

</profile>

</system.web>

Step two: Using Profile in VS2005

Write profile to Database

if (User.Identity.IsAuthenticated)

{

Profile.name = txtName.Text;

Profile.age = Convert.ToInt32 (Txtage.text);

Profile.school = Txtschool.text;

Profile.other.birthday = Convert.todatetime (Txtbirthday.text);

Profile.other.blood = Txtblood.text;

}

To read the profile from the database to the page

if (User.Identity.IsAuthenticated)

{

txtName.Text = Profile.name;

Txtage.text = Profile.age.ToString ();

Txtschool.text = Profile.school;

Txtbirthday.text = Profile.other.birthday.ToString ();

Txtblood.text = Profile.other.blood;

}

Step three: View the Aspnet_profile table and you will find the information that you have added to your customizations.

3. Update Profile user settings file

First step: Set up the Web. config file

Step Two: Add the update code

if (User.Identity.IsAuthenticated)

{

Profile.name = txtName.Text;

Profile.age = Convert.ToInt32 (Txtage.text);

Profile.school = Txtschool.text;

Profile.other.birthday = Convert.todatetime (Txtbirthday.text);

Profile.other.blood = Txtblood.text;

Profile.save ();

}

Step three: Look at the Aspnet_profile table and you will find the information that modifies your customizations.

(Che Yanlu)

Collected in 2007-06-29

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

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.