[ASP. NET Notes] 8. ASP. NET built-in Image

Source: Internet
Author: User
1: SessionObject
2: Application Object
3: cookies

4: Global ApplicationProgramClass global. asax

Session [session] Object
How the session object works:
1: First, you should think of the session as a big box to store customer data.
2: When you open the homepage of a website, the server will create a large box for you and create a number for the big box, therefore, this big box allows you to share different pages of the website. the server will reclaim the large box when you leave the website.
3: it can be seen that one of the functions of the session object is to allow users to share data between different pages. However, once the user leaves the website, the session will automatically disappear.
4: a website can be accessed by many people at the same time. When a visitor opens the home page, there will be a large box called session. if another user accesses the website at the same time, he also has his own session variable, but the two users cannot share information through the session
6: sesson is a collection of data.
7: session refers to the period from when a visitor arrives at a specific homepage to when the visitor leaves.

Use swimming to allocate a Cabinet as an example to describe sesson's usage

Summary: session can provide support for sharing between different pages of the same user. This support is maintained on the server side.

A) how to add or modify a data entry to a session
Session ("keyword") = Value
B) how to obtain the value of each keyword in the session
1) Session. Contents (subscript)
2) Session. Contents ("keyword ")
C) how to obtain the number of data in the session
Session. Contents. Count
D) How to Find each number in the session set
For I = 1 to session. Contents. Count
Response. Write session. Contents (I)
Next
E) how to delete a data item in the session set
1) Session. Contents. Remove (subscript)
2) Session. Contents. Remove (keyword)
F) how to clear all data in the session set
Session. Contents. removeall ()
G) how to set the expiration time
The session is retained on the server for a limited time. The default value is 20 minutes.
Session. Timeout = value (in units)

session application example
Example 1: restrict the modules that can be used by users based on the types of logged-on users.
Example 2: determine whether a user logs on to determine whether the user can shop
Example 3: simple shopping cart. Using hastable


Application Object
The Session Object records the information of a specific customer, while the application object records all the customer information. For example, a public storage cabinet in a classroom can be used by every student. Application is typically a chat room. All speeches are stored in an application object. You can see the content of the speech. The content of the application object is stored on the server. The application object does not have the image validity limit as sessoin. It always exists. Information from any client will not be Diu lost between the application startup and application shutdown.

1) application. Lock: Lock the application image to prevent other customers from simultaneously modifying the image of applicaton.
2) application. Unlock: Unlock to allow access by other customers.
3) Application ("keyword") = value ---> assign a value to the application

Application Example of applicatoin
1: Simple Chat Room [display the name, content, and time of the speaker]
2: count the number of visits on the webpage in graphics

Cookie object
What is cookies?
Cookies can be stored on the client for a long time. There is a cookie folder in the client's computer, which stores client information. Different from session and application,
Cookies store information on the client, not on the server. When you visit a website for the first time, the server will save the information in the cookies folder on your computer's hard disk,
The next time you access this website, it will read cookies on your computer's hard disk and save new information on your computer.

Cookies:
1: Temporary cookies ---> expires is not set. Cookies are stored in the client memory,
When the browser is closed, the corresponding cookies are automatically cleared.
2: Permanent cookies --> expires is set. It is stored in the customer's hard disk. You can obtain


Cookies
1) response. Cookies ("keyword") = values written into cookies
2) variable name = request. Cookies ("keyword") read
3) response. Cookies ("keyword"). expires = # date #
Set the expiration time of cookies as permanent cookies. Note that the setting is after response. Cookies ("keyword") = Value

Application Example
1: count the number of times a client has visited a website [set to permanent cookies]
2: Save the username or password you have filled in
3: Birthday reminder

Global Application class global. asax
Some events are predefined in the global application class and can be written in the event.CodeTo achieve the purpose of statistics

example:
1) number of online users
2) Number of visitors to a website

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.