What is a session?
session refers to a user's access to a site over a period of time.
The session object corresponds to the HttpSessionState class in. NET, which means "conversation state", which can hold information related to the current user session.
The Session object is used to store the information that is required for a particular user session from the beginning of a user's access to a particular ASPX page, until the user leaves. The variables of the session object are not cleared when the user switches the application's page.
How do I use the session?
For a Web application, the content of the Application object accessed by all users is exactly the same, while the content of the session object accessed by different user sessions varies. Session can save the variable, which can only be used by one user, that is, each Web browser has its own session object variable, that is, the session object is unique.
(1) Add a new item to the session state in the syntax format:
Session ("key name") = value
Or
Session.add ("Key Name", value)
(2) The value in the session state is obtained by name in the syntax format:
Variable = Session ("Key Name")
Or
Variable = session.item ("Key Name")
(3) The item syntax format in the delete session-state collection is:
Session.remove ("Key Name")
(4) All values in the session state are cleared in the syntax format:
Session.removeall ()
Or
Session.clear ()
(5) Cancel the current conversational format as:
Session.Abandon ()
(6) Sets the time-out period for session state, in minutes. The syntax format is:
Session.Timeout = value
2 events in the Global.asax file are applied to the session object
Event name Description
Session_Start fires when a session is started
session_end fires at the end of a session
Session summary
at the time of writing a program, especially a very large program, some information exists in the session, to achieve the value between the interface. If you use get parameters, it is unsafe to use. Using session can make access more secure.
The session also has some shortcomings, process dependencies, the use of the session state limitations and so on.
Use of session in. Net