Application, session, Cookie, viewstate, and Cache

Source: Internet
Author: User

Application1. application is used to save information shared by all users. 2. In the ASP era, it is ideal to use application if the data to be stored does not or rarely change during the lifetime of the application. 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 (); Session1. session is used to save the proprietary information of each user. the lifetime of the session is the user's continuous request time plus a period of time (usually about 20 minutes) 3. session information is stored in the memory of the Web server. The stored data size can be large or small. session Timeout or shutdown will automatically release data. this method is less efficient because it remains in the memory for a period of time after the user stops using the application. code: session ["userid"] = "test"; string username = session ["userid"]. tostring (); Cookie1. cookie is used to save the request information of the client browser request Server Page. 2. we can store non-sensitive user information and set the storage time as needed. if no cookie expiration date is set, its lifecycle is saved until the browser is closed. 4. the expires attribute of the cookie object is set to minvalue, indicating that the object will never expire. the amount of data stored in cookies is limited. Most browsers use 4 K, so do not store or enlarge data. 6. because not all browsers support cookies, data is stored in plain text on the client. code: resopnse. cookies ["userid"] = "test"; string username = resopnse. cookies ["userid"]. tostring (); Viewstate1. viewstate is used to save the user's status information. The validity period is equal to the lifecycle of the page. you can store a large amount of data, but use it with caution because it will affect program performance. all Web server controls use viewstate to save the status during page PostBack. if this parameter is not required, enableviewstate = false5. code: viewstate ['"Id"] = "yiner" is disabled in @ page ";
String id = viewstate ["ID"]. tostring (); Cache1. 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. it can be seen that the 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: If you want 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 (); Hidden1. the hidden control is an HTML-type server control that 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

 

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.