Introduction and Induction of asp.net Page Status

Source: Internet
Author: User

Yesterday I spent some time summing up the ASP. NET status. I hope you can help me supplement or correct it. Thank you ~~

 

Display content

 ASP. NET page status Difference Analysis
1. Application is a global state variable on the server. It is used to save some public information, rather than storing some personal information. This status ends when the website system is disabled. The status saved by the Application is accessible to each page. The status exists and disappears only when the website service is disabled during the entire service running period. Session is often used to save the user status and disappears when the page is closed.
Sample Code: "Settings:
Application. Lock ();
Application ["" key ""] = "" value "";
Application. UnLock ();
Read:
Response. Write (Application ["key" "]. ToString ());"
2. the Cache is similar to the Application and is also a global state variable on the server. The use of Cache can greatly improve the efficiency of the entire application. Note: To use functions such as Cache cleanup, expiration management, and dependency items, you must use the Insert or Add method to Add information Cache. Besides the Application function, some of its own features are automatically updated and released. Therefore, Cache is more flexible than Application.
Sample Code: "set: Cache [" key ""] = "" value ""; or Catch. Insert ("" key "", "" value "");
Read: Response. Write (Cache ["" key ""]);"
3. Cookie "is used to save the request information of the client browser's request Server Page. Its validity period can be set manually, and the data size stored is very limited. Therefore, do not save datasets and other large amounts of data. Moreover, cookies store data in plain text on the client's computer, so it is best not to store sensitive unencrypted data.
Note: You can manually clear the Cookie in the browser or hard disk, or make the Cookie instance expire in the program. "The status information saved by the Cookie exists in the user's hard disk.
Application and Cache disappear when the service is closed, and will not disappear when the page is closed as in Session. They will only disappear when the service expires or the Cookie-related files are cleared"
Sample Code: "create: Response. cookies ["" key ""] = "" value ""; or HttpCookie myCookie = new HttpCookie ("" key ""); myCookie. value = "" value "";
Read: Response. Write (Request. Cookies []. Value) or Response. Write (myCookie. Value );
Delete: Response. cookies ["key"]. expires = DateTime. now. addDays (-1); or Response. cookies ["key"]. expires = DateTime. now. addDays (-1); myCookie ["key" "]. expires = DateTime. now. addDays (-1); Note: You can also use multiple keys to define cookies, for example, Response. cookies ["" key1 ""] ["" key2 ""] = "" value;
"
4. The HiddenField Hidden control is an Html-type server control that can hide a domain. It is no different from other spaces except that it is not displayed in the browser and is always Hidden. "HideenField, as a hidden function, can only save information on its own page, similar to ViewState. However, it can only store string data types. But it is almost replaced by ViewState,
"
Sample Code: "// store information
Hidden. Value = "" value "";
// Read information
String s = Hidden. Value;
"
5. QueryString is a URL request, for example, by linking to http: // localhost/default. aspx? Name = namevalue. You can pass the value namevalue to the default. aspx page "Request. QueryString, that is, write the variable value after the url and pass it
Page, the variable will end when the page is closed"
Sample Code: "Pass: http: // localhost/default. aspx? Name = namevalue
Read: Response. Write (Request. QueryString ["" name ""]);"
6. Session is used to save the dedicated information of each user. The Session information is stored in the memory of the Web server, and the stored data volume can be large or small. The stored data is automatically released when the Session times out or is disabled. It is a good choice to save a small amount of data Session objects. "Similar to Application usage, but it does not have a wide range, and it fails when the page is closed or times out.
"
Sample Code: "storage Information: Session [" key ""] = "" value "";
Read Information: Response. Write (Session ["key" "]. ToString ())"
7. ViewState "ViewState is often used to save the state information of a single user. It can save a large amount of data, but excessive use of it will affect the application performance. All Web server controls use ViewStat to save their own status information during page sending. Each control has its own ViewState. It is best to disable it when not in use to save resources. You can disable the ViewState of the entire Page by adding the "" EnableViewState = false "attribute to the @ Page command.
Note: ViewState cannot be transferred across pages. The value range is narrow and can only be saved on pages.

 

 

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.