[Reprint] Application Session Cookie viewstate cache hidden in Asp.net

Source: Internet
Author: User

I think it is very useful. keep one copy. OriginalHttp://www.cnblogs.com/me-sa/archive/2007/07/04/80...

Application

1. The application is used to save information shared by all users.

2. In the ASP era, if you want to store data in applicationsProgramApplication is an ideal choice if no or few changes occur during the lifetime. However, in the Asp.net development environment, we put similar configuration data in Web. config.

3. if you want to use the application, note that all write operations must be completed in the application_onstart event (Global. asax), even though application. lock () avoids conflicts, but serializes application requests, which can cause serious performance bottlenecks.

4. Do not use application to save large data volumes.

5.Code: Application ["userid"] = "test ";

String username = application ["userid"]. tostring ();

Session

1. Session is used to save the proprietary information of each user.

2. The session lifetime is the user's sustained request time plus a period of time (generally about 20 minutes)

3. The session information is stored in the web server memory, and the stored data volume can be large or small.

4. Data will be automatically released when the session times out or is disabled.

5. This method is inefficient because it remains in memory for a period of time after the user stops using the application.

6. Code: session ["userid"] = "test ";

String username = session ["userid"]. tostring ();

Cookie

1. Cookie is used to save the request information of the client browser requesting the Server Page

2. We can store non-sensitive user information and set the storage time as needed.

3. If no cookie expiration date is set, its lifecycle is saved until the browser is closed.

4. Setting the expires attribute of the cookie object to minvalue indicates that the object will never expire.

5. The amount of data stored in cookies is limited. Most browsers use 4 K, so do not store magnified data.

6. Because not all browsers support cookies, data will be stored in plaintext on the client.

7. Code: resopnse. Cookies ["userid"] = "test ";

String username = resopnse. Cookies ["userid"]. tostring ();

Viewstate

1. viewstate is used to save the user's status information. The validity period is equal to the lifecycle of the page.

2. You can save a large amount of data, but use it with caution because it will affect program performance.

3. All Web server controls use viewstate to save the status during page PostBack.

4. Disable enableviewstate = false in @ page if not required.

5. Code: viewstate ['"Id"] = "yiner ";
String id = viewstate ["ID"]. tostring ();

Cache

1. cache is used to save pages or data during HTTP requests

2. The use of cache can greatly improve the efficiency of the entire application.

3. It allows you to store frequently accessed server resources in the memory. When the user sends the same request
Instead of processing the data again, the server directly returns the data saved in the cache to the user.

4. We can see that cache saves time-server processing time

5. the cache instance is exclusive to every application, and its lifecycle = This application cycle
Restart the application and re-create its instance

6. Note: To use functions such as cache cleanup, expiration management, and dependency items, you must use the insert or add method to add information.

7. Code: cache ['"Id"] = "yiner"; or cache. insert ("ID", "test ");
String id = cache ["ID"]. tostring ();

Hidden

1. The hidden control is an HTML-type server control and is always hidden.

2. Each time it is submitted, it will be submitted to the server together with other server controls.

3. The Code is as follows: hidden. value = "King ";
String id = hidden. value; Use runat = Server

Related Article

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.