Read petshop code (profile)

Source: Internet
Author: User

It is used to store user-related data and maintain the application status. The profile object provides a method for creating session States with strong and persistent modes.

Use profile. shoppingcart. Add ();

Profile. Save ();

For example

The configuration file code is as follows:

Code
<Profile automaticsaveenabled = "false" defaultprovider = "shoppingcartprovider">
<Providers>
<Add name = "shoppingcartprovider" connectionstringname = "sqlprofileconn" type = "petshop. profile. petshopprofileprovider" applicationname = ". Net Pet Shop 4.0"/>
</Providers>
<Properties>
<Add name = "shoppingcart" type = "petshop. BLL. Cart" allowanonymous = "true" provider = "shoppingcartprovider"/>
</Properties>
</Profile>

According to the configuration file, the property that needs to be stored is petshop. BLL. cart, and the Custom User Configuration provider is shoppingcartprovider, which stores related information in the petshop. BLL. Cart class. Because shoppingcartprovider is a Custom User Configuration provider, it must inherit from system. web. profile. profileprovider, override some methods in the parent class, such as initialize (), getpropertyvalues (), setpropertyvalues (), and so on.

Start the web application. ASP. NET creates an instance of the profilecommon Class Based on the configuration file. This class inherits from the system. Web. profile. profilebase class. According to some code of the profilecommon class

Code
Public Virtual petshop. BLL. Cart shoppingcart {
Get {
Return (petshop. BLL. Cart) (This. getpropertyvalue ("shoppingcart ")));
}
Set {
This. setpropertyvalue ("shoppingcart", value );
}
}

 

Call the override initialize () method to set the options and initial values of the provider instance. Then. getproertyvalue ("shoppingcart"), call the getpropertyvalues method to obtain the relevant property type petshop. bll. after the information in the cart (stored in the database), perform a forced conversion (petshop. bll. cart) (this. getproertyvalue ("shoppingcart"), and then calls cart. add () method.

After the profile. Save () method is called, the program calls the repeated method setpropertyvalue () in shoppingcartprovider to save related information in petshop. BLL. Cart.

Go to: http://www.cnblogs.com/sunny0311/archive/2008/09/22/1296241.html

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.