This section describes several methods for transferring data between ASP. NET pages and their advantages and disadvantages?

Source: Internet
Author: User

 

1) Request. querystring is a commonly used method in the ASP era. net, it seems that there are not many people to use, but in any case, this is not outdated, and it is worth recommending, because either ASP or ASP. net, the most basic is based on the HTTP protocol. The disadvantage is that the request may fail when multiple pages are passed.

2) session is the most commonly used method. The advantage of session is that it is easy to use, but the disadvantage is that it occupies server resources, because each session means that the server needs to maintain the session information of the corresponding customers, naturally, if there are more login users, the server resources will be very occupied. In addition, the session also has a disadvantage. By default, if you do not perform any action within 20 minutes after logon, the server will automatically cancel the session, so you need to log on again. PS. This reminds me of one thing. A company showed me a piece of code a few days ago. When I log on, I used session to record user logon. My God, microsoft knows that it must vomit blood !! It has worked hard to provide you with web. the configuration in config <deny user = "*"/> requires this configuration. You don't need to use the session in the ASP era. It's not a waste of Ms painstaking efforts.

3) application is still quite common in the ASP era. It is mainly used to store global variables, such as database link information, to ASP. net Era, not used much, at least I seem to have never used it.

4) CookieThis is my favorite,The biggest feature of cookies is thatMaintained by the client without occupying server resourcesAnd you can set the cookie validity period during user login, for example, one day. In this way, you do not have to worry about logging on to the system again within one day. Of course, cookies also have disadvantages, that is, security. Because cookies are on the client, some software can analyze the login information of cookies. Therefore, do not be too sensitive to the content written into cookies, for example, do not store passwords, also, for security purposes, it is best to encrypt the content written into cookies.

5) viewstate added by ASP. NET. viewstate is easy to use. Its disadvantage is that it can only be used on the same page. In ASP. net2.0, The postbackurl of the button can be used for the result.

6) there is not much to think about using the cache to store data, but it is also a method. In addition, when using the cache to store dataset, it is still a reference instead of a copy of the content.

I. Currently, there are several methods for passing values on pages in ASP. NET:

1. Form submission, <form action = "target. aspx "method =" Post "name =" form1 "> <input name =" param1 "value =" 1111 "/> <input name =" param2 "value =" 2222 "/> </form> .... form1.submit ();.... this method is implemented in ASP. Net is invalid because ASP. . Net forms are always submitted to their own pages. If you want to submit other pages, special processing is required.

2. <a href = "target. aspx? Param1 = 1111 & m2 = 2222 "> link transfer </a> receiving page: String STR = request [" param1 "]

3. Session sharing sending page: Session ("param1") = "1111"; by receiving page string STR = SESSION ("param1"). tostring ();

4. Application shared sending page: Application ("param1") = "1111"; by receiving page: String STR = Application ("param1 "). tostring (); this method is not often used. Because the application is shared within an application domain, all users can change and set its value. Therefore, only the counters and other places that require global variables are used.

5. Cookie

6. response. Redirect () method response. Redirect ("target. aspx? Param1 = 1111 & m2 = 2222 ") receiving page: String STR = request [" param1 "]

7. server. Transfer () mode. Server. Transfer ("target. aspx? Param1 = 1111 & m2 = 2222 ") receiving page: String STR = request [" param1 "]

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.