Several common methods for passing parameters between pages in Asp.net, and their respective advantages and disadvantages

Source: Internet
Author: User

1. Two commonly used page redirection Methods

(1) The redirect method redirects the client to the new page. It simply terminates the current page and transfers it to the new page for execution. There is no restriction on the page to be transferred.

(2) The transfer method terminates the execution of the current page and executes a new page for the current request. The execution process is transferred from the current page to another page on the same server, but the new page still uses the response stream created on the current page.

The main differences between the two methods are: (1) the Redirect method can achieve redirection between any web pages, while the transfer method can only achieve redirection between aspx pages on the same server.

(2) The redirect method does not retain the form data and query string (querystring) of the current page, while the transfer method can retain the data.

2. The use of querystring is the simplest and most commonly used value passing method, which corresponds to the traditional get method and has a relatively small change. Data is directly transmitted in plaintext in the URL, which is visible to users but can be encrypted. This method is simple and convenient. Its disadvantage is that the amount of data that can be transferred is small and objects cannot be transferred.

3. The use of Form to transmit data through the controls in the form is relatively large in contrast to the traditional post method.

This method can transmit a large amount of data and access the data in the Source Page Control. The disadvantage is that the operation is complicated and the lifecycle is limited to the current request.

4. The sessionss object used by the session provides information for the current user session.

Its attributes allow you to easily set and retrieve ASP.. Net session status variables, whose values remain unchanged during the session duration and can be accessed by all pages in the same session. This provides a convenient way to pass the page value.

This method has the following features:

(1) user data is stored on the server;

(2) Session objects in ASP. NET can also work normally without relying on cookies;

(3) objects can be stored directly without the size limit;

(4) The validity period is related to the user's activity time, specifically the user activity time + custom delay time. The disadvantage of this method is that because the web application generates session variables for each user, it will increase the server load as the number of users increases. If the data volume is small, the sessionss object is an excellent location for saving the specific data that needs to be kept in the current dialog.

5. cookic: the disadvantage of this method is that not all browsers support cookies. Users can disable and delete cookies. Information is saved in plaintext, which is less secure. When a specific user needs a specific data segment and maintains the data in a variable period, the cookie is very convenient and exists on the client without occupying server resources.

6. Static: static variables may be called directly by class names. The advantage is that, if well-utilized, data transmission efficiency can be effectively improved. The disadvantage is that, if misuse is made, this can cause data disorder between users or pages and cause great risks.

7. cache buffer mechanism. A large number of server resources are used to create content in the server memory to improve the application performance. The advantage is that there is no limit on the size and quantity of transmitted parameters, and the speed is fast. The disadvantage is that when there are too many buffers, the server uses Priority sorting as the buffer to clear small ones that are not commonly used. As a result, the passing of parameters fails and the relative operation mechanism is also complicated.

8. The context object contains information related to the current page and provides access to the entire context, including the request, response, and session and application information. You can use this object to share information between webpages so as to transmit values between pages. Similar to the form method, this method can maintain a large amount of data with the same disadvantages, but the method is relatively simple.

9. viewstate is a mechanism used by ASP. NET to save and restore the view status of server controls between multiple requests on the same page. Unlike the traditional "Same page", every request of "Same page" in ASP. NET will cause the server to regenerate the page, but the newly generated page does not contain the data of the original page. The viewstate task is to save the Server Control view status data on the original page for the new page. In this sense, viewstate can also be seen as a tool for transferring data between pages. Viewstate is transmitted between the client and the server as a hidden form field. We can see that misuse of viewstate increases the burden of page return and reduces the performance of applications.

10. Web. config and machine. config are used to set some attributes of each ASP. NET application. The machine. config file is used to set the basic information of all applications. The data stored in these two types of files is usually very small and mostly in plain text. It is especially suitable for storing some string constants, such as database connection information. In addition, the web. config file can be expanded, so it can also be used to pass variables. Because these two files are automatically cached, there is no performance bottleneck caused by disk I/O.

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.