How to save variables in Asp.net requests

Source: Internet
Author: User

Session:

The current browser user expires after the browser is closed or after a specified time (20 minutes by default ).

At the same time, according to the session storage method, there are different situations:

  • Inproc: In this mode, the session will be saved in the IIS process. If the IIS process is restarted, the session will be lost.
  • StateServer: Session will be stored in ASP. in the net state service process, the restart of the IIS process will not cause session failure, only ASP.. Net state service process will not expire after being restarted. When session is stored in this mode, the ASP. Net state service process can be in a different PC than IIS.
  • SQL Server: Use sqlserver to save sessions. This is the safest solution. Session values are stored in the database using data information.

When you use StateServer and sqlserver to save the session, because the object is not transmitted in a process, this object must be serializable ([serializable]).

Viewstate:

Valid on current client and current page

Storing too much data will seriously affect the page reading efficiency

COOKIE:

Valid on the current machine. You can specify the expiration time.

Static variable:

Stored on the server, shared by all users

Static variables are stored in the corresponding class on the page. If the object on the page is recycled, static variables are also recycled.

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.