Use of session in. Net

Source: Internet
Author: User

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

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.