Several ways to pass the value of ASP.

Source: Internet
Author: User
Tags value store

Http://www.cnblogs.com/makqiq/p/5882448.html

1.Querystring

QueryString is also called query string, which passes data between pages using the URL of the Web page address. If you want to jump from page A to page B, you can use Request.redirect ("b.aspx?name= parameter Value") and receive parameters with ruquest["parameter name" after the page jumps. request.querystring["name"] and get request.form["name"] and post

This method is simple to use without server resources. However, it is easy to tamper with and cannot pass objects, and it is only possible to query strings when requesting a page through a URL.

2.ViewState

This is a hidden form field that is managed by the ASP. viewstate["variable name" can be used when using the]= value, when fetching data: variable = viewstate["variable name"];

ViewState in the same page when multiple requests back automatically retain values, without server resources, with hashed format storage; Because viewstate is stored in the page, the user page slows down when a larger value is saved. Although it is a hash value store, it will still be tampered with maliciously.

3.Cookie

The Cookie uses response.cookie["key Name"] = value; take data variable = request.cookie["key Name"].

Cookies are stored in the client and are suitable for storing information that is less frequently changed, without server resources, and configurable due time. However, cookies may be disabled or removed from the client because it is plaintext text and it is not appropriate to store sensitive and unencrypted data.

4.Application

Application is a global variable, and all users share a application variable. Use application["variable name"]= value, Value: variable = Application ["Variable name"], clear it with: application["variable name"] = NULL;

application can be accessed for all pages in the program, but if the server fails the data will be lost.

5.Session

The session is used in the same way as application. Session objects are used to store conversation information, and different client-generated sessions are used for short-term information that is specific to a separate session. It is easy to implement and provides high security and durability, and can be used in multiple processes for IIS restart and worker process restarts. The disadvantage is that it consumes server-side memory. So don't store a lot of information. The most common use of a session is to provide a user identity function with a cookie to a Web application, and the session can also be used for browsers that do not support cookies. However, using a session without a cookie requires that you place the conversation identifier in the query string, as well as the security issues that are stated in the query string section of this article.

6.Cache

The Cache has powerful data manipulation capabilities to store data in the form of key-value pairs, and you can insert and retrieve data items by specifying keywords. Its dependency-based termination feature enables it to precisely control how and when data in the cache is updated and eliminated. It can be managed internally, without the need for serialization management using the lock () and Unlock () methods, as application objects do. Disadvantage is that the use of the method is more complex

7.server.transfer

How to use it under different circumstances:

Situation one: The source page can jump to the target page, the source page to pass the data to the target page

Using a query string to transfer a small amount of information from one page to another and without security issues is a simple and common method, using the Server.Transfer method, you can pass the form data or query string to another page, and you can save the HttpContext of the initial page. This method can be used when the target page and the source page are on the same server.

Scenario Two: page passing values to itself page

That is, the ViewState property provides functionality with basic security while preserving values between multiple requests on the same page. You can also use a hidden field to store a small amount of postback to itself or another page of page information when used without regard to security issues.

Scenario Three: The source page passes values to the target page, and the source page cannot be connected directly to the target page.

Application: Stores global information that is used by multiple users and changes infrequently, and security is not a problem at this time. Do not store large amounts of information. Session: Stores short-term information that is specific to a separate session and requires high security. Do not store large amounts of information in session state. It is important to note that session-state objects are created and maintained for the lifetime of each session in the application. In applications that support many users, this can consume a lot of server resources and affect scalability.

Cookies: used when you need to store a small amount of information on the client and there is no security issue. A static property of the class that facilitates the transfer of multiple data.

Cache: Objects are used for a single user, a group of users, or all users. Data can be saved for a long time and efficiently for multiple requests. The above methods, not only for the situation of three, the previous two cases can be used, but not necessary to minimize the use, otherwise it will cause waste of resources or increase the complexity of the program

Several ways to pass the value of ASP.

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.