Details on defining profile User Files

Source: Internet
Author: User

Summary:The profile user setting file is used to store the user's personal unique data. To run the profile setting file, you must first identify the user, whether it is verified or anonymous, once the user is uniquely identified, the user information can be stored in profile-related data tables. Simply put, the profile function is used in combination with the functions of the login component, the login component records the key information of users, including the user name, password, email address, security questions, and answers, however, other information associated with a user, such as the constellation, blood type, and other basic information, is stored in the profile file.

1. Define the profileUser Files

To add a profile user setting file to a website, you only need to set it in the web. config file:

<System. Web>

<Profile>

<Properties>
<Add name = "country" type = "system. String" defaultvalue = "China"> </Add>
// Some attributes can be stored at a fixed level. For example, the attribute of the above country is fixed to "China"

<Add name = "gender" type = "system. String"> </Add>

<Addname = "constellation" type = "system. String"> </Add>

<Add name = "" type = "system. String"> </Add>

</Properties>

</Profile>

</System. Web>


2. Add a profile for a specific userInformation

After user authentication, you can add user information in the following ways:

Profile. Gender = textbox1.text. Trim ();

Profile. constellation = textbox2.text. Trim ();

Profile. Education Level = textbox3.text. Trim ();

Profile. Save (); // save user information

3. Read user-related information

In the database, the profile file information is stored using the following style:


(1) You can read the profile information of a user in the following ways:

If (! Ispostback)

{

Profilecommon USERPROFILE = profile. getprofile (membership. getuser (). tostring ());

// Obtain information about the current user, mainly the user name.

Label1.text = USERPROFILE. Gender;

Label2.text = USERPROFILE. constellation;

Label3.text = USERPROFILE. education level;

}


(2) In addition, you can classify the fields defined in the profile to facilitate management. For example, the country and city fields can be classified into address groups, you only need to use profile. the address's intelliisense can be called to the above fields. The settings are as follows:


The call method is as follows:

Label5.text = USERPROFILE. Address. City + USERPROFILE. Address. Age. tostring ();

Iv. ProfileHow Files Work

Three main classes are involved in this operation process:

Profile

Profile, profilecommom, and profilebase classes have the following relationships when reading a user's profile file:

 

 

 
 

 

 

5. Update the profileUser setting file

Profile. Gender = textbox1.text. Trim ();

Profile. constellation = textbox2.text. Trim ();

Profile. Education Level = textbox3.text. Trim ();

Profile. Save (); // The save operation here is an update operation, not a save operation.

6. Read the profile of all usersSet File

(1) After you bind the names of all users to the dropdownlist, you must set the autopostback attribute of the dropdownlist to "true" to the event triggered after the dropdownlist option is changed ";

(2) Compile the selectedindexchanged event of dropdownlist and bind the selected user's profile file information to the data source of the gridview:

Profilecommon USERPROFILE = profile. getprofile (dropdownlist1.selecteditem. Text );

If (profilecommon. properties. Count> = 0)

{

Datatabletable = new datatable ();

Table. Columns. Add ("Profile attribute name", typeof (string ));

Table. Columns. Add ("Profile attribute value", typeof (string ));

Datarowsinglerow;

 

Singlerow = table. newrow ();

Singlerow ["Profile property name"] = "User Name ";

Singlerow ["Profile attribute value"] = USERPROFILE. Username;

Table. Rows. Add (singlerow );

 

Singlerow = table. newrow ();

Singlerow ["Profile attribute name"] = "constellation ";

Singlerow ["Profile attribute value"] = USERPROFILE. constellation;

Table. Rows. Add (singlerow );

Gridview1.datasource = table;

Gridview1.databind ();
Foreground file:


Background File:

6. Profile of anonymous users on the websiteFile Information

(1) The information of anonymous users on the website is not invisible. The website can normally record the guid code of anonymous users on the website, that is, the unique identifier of anonymous users, however, this feature is not recorded by default. You need to enable this feature in the configuration file:

(

2) record the basic information of anonymous users. The displayed user information is as follows:

(

3) store and use the profile setting file of an anonymous user, provided that. anonymousidentification must be set to true (that is, the profile function of anonymous users is enabled); B. the attribute of the profile field must also be set to true for allowanonymous;

 

The database is stored as follows:

VII. Anonymous user profileFile Information migration (Migration)

(1) Add a transfer event to the Global File global. ascx.

 

 

The code for the global file is as follows:

<% @ Applicationlanguage = "C #" %>

<SCRIPT runat = "server">

Voidapplication_start (Object sender, eventargs E)

{

// Code that runs when the application starts

}

Voidapplication_end (Object sender, eventargs E)

{

// Code that runs when the application is closed

}

Voidapplication_error (Object sender, eventargs E)

{

// Code that runs when an unhandled error occurs

}

Voidsession_start (Object sender, eventargs E)

{

// The code that runs when the new session starts

}

Voidsession_end (Object sender, eventargs E)

{

// The code that runs when the session ends.

// Note: Only the sessionstate mode in the web. config file is set

// The session_end event is triggered only when inproc is used. If the session mode is set to StateServer

// Or sqlserver, the event is not triggered.

}

Voidprofile_migrateanonymous (Object sender, profilemigrateeventargs ARGs)

{

Profilecommonanonymousprofile = profile. getprofile (ARGs. anonymousid );

// Transfer the personal interests of anonymous users to the personal interests of login users

If (! String. isnullorempty (anonymousprofile. My hobbies ))

{

Profile. Personal Interests = anonymousprofile. personal interests;

Profile. Save ();

}

// Delete the profile of an anonymous user

Profilemanager. deleteprofile (ARGs. anonymousid );

// Clear cookies or identity information of Anonymous Users

Anonymousidentificationmodule. clearanonymousidentifier ();

}

</SCRIPT>

In this way, some choices of anonymous users can be added to the names of users who log on later. For example, when an anonymous user logs on to the website and puts some items in his/her shopping cart, when you borrow money, you can transfer these items to your own user name.

VIII. profilemoduleClass

This class is used to create a user profile and manage profile events. Its operating principle is ASP. NET profile is enabled, Asp. net uses the profilemodule class to create a user profile and store it in the current profile attribute of httpcontext. There are three main events managed by profile: migrateaonnymous (anonymous profile migration event), personalize (profile personalized events), profileautosaving events.

You can view details about the specific functions of each event.

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.