Asp. NET session

Source: Internet
Author: User
Tags set time

Introduction Edit Session objects are used to store the information required for a particular user Session. The introduction of the session object is to compensate for the lack of HTTP protocol, the HTTP protocol is a stateless Protocol. Session Chinese is the meaning of "conversation", which represents the "session" between the server and the client in asp. The Session's action time starts when the user arrives at a specific web page, either to leave the Web site or to end a session with code in the Program. Referencing a session allows a user to access the switch between multiple pages and also preserves the User's Information. The system sets up a separate session object for each visitor to store session variables, and each Visitor's session object does not interfere with each other. The session is closely related to Cookies. The use of the session requires that the User's browser must support cookies, and if the browser does not support the use of cookies or is set to disable cookies, the session will not be Used.

Session information to the customer, different users with different session information to Record. When the user enables the session, the ASP automatically generates a sessionid. at the beginning of a new session, the server stores SessionID as a cookie in the User's browser.

using editors The collection, properties, methods, events of the Session object
Name Describe
Contents Collection Contains all data items that are added to the application through script commands
SessionID Property Used to identify each of the session objects
Timeout property The time-out (in Minutes) used to set session sessions
Abandon method Forcibly deletes the session object of the current conversation and frees up system resources
Session_OnStart Events Events that are fired when a session object is created
Session_OnEnd Events Event that fires when the session object is ended
StaticObjects Collection Contains all objects added to the application through the <OBJECT> tag

Session profile, Features

1.Session is one of the common states in a Web Session.

2.Session provides a way to keep information in the Server's memory. He can store any data type, including a custom Object.

3. The seesion of each client is stored independently.

4. During the entire session, as long as the SessionID cookie is not lost, the session information will be Saved.

5.Session cannot be accessed across processes, only by users of that Session. The ID identification of the session data should be saved in a cookie to the Visitor's browser's Cache.

6. When the session terminates, or expires, the server clears the session Object.

7.Session is often used to save the ID of the logged-on user.

8.Session saved data is cross-page global

Session principle (as explained in the above Example)

How is the session stored and extracted?

1. On the server side there is a session pool, used to store each user submits session data , session for each client (or browser Instance) is a "hand", the first time the user to establish a connection with the Web server, The server distributes a sessionid as an identity to the User. SessionID is a random string of 24 characters. Each time the user submits the page, the browser will include this SessionID in the HTTP header to the Web server, so that the Web server can distinguish between the client on the current request page, and this sessionid is a cookie stored in the Client's memory, If you want to get the data from the session pool, the server will give the corresponding data return based on the unique SessionID ID submitted by the Client.

2. Enter the correct account password, Click login, the page will output "admin---click login"

How is the data of each client in the session pool stored?

1. the data stored in the session pool is a global data that can be accessed across pages, Only the unique data is stored in each sessionid, such as: first you set up: session["userName"]= "admin", and then you in the session is not over the end of the event has not expired, you also set: session["userName"] = "123", so the SessionID is unchanged, but the data in the session pool is Overwritten. At this point the value of session["userName" is "123", not the Other.

2.session pool cannot be accessed across Processes. Such as: open login.aspx page Write session["userName"]= "admin"; then the login page does not close, that is, this session does not end, in this case you will open a Login.aspx page in another browser session[" UserName "]=null

3. Enter the account password, click the login page output "admin---click login", If you click to get the session button, then the page only output "admin---click get session", If the page does not close, open another browser, Click the Get session button, then the page will not be able to.

The declaration period and destruction of the session

1.session Storage Data timing is a scrolling timing method. specifically, If you open the write session, from the beginning of writing, This page if there is no commit operation, the default time is 20 minutes, 20 minutes after the session is automatically destroyed by the server, if there is a commit operation, the server will be re-timed after the submission and so on, until the set time to Destroy.

2. You can set the time for the session to be Destroyed. The above code is Mentioned.

four, The session is stored in the data is on the server, and each user, such as login operation, the session data will be written, so it is recommended to use the session cautiously, is less use.

Asp. NET session

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.