Introduces several methods of data transfer between ASP.net pages, and introduces the advantages and disadvantages of some of these methods. __.net

Source: Internet
Author: User

1 request.querystring in the ASP era, this is a more commonly used method, To the ASP.net, it seems that there are not many people, but anyway, this is a no outdated, and very recommended method, because whether it is ASP or asp.net, the most basic is based on the HTTP protocol. The disadvantage is very obvious, so that when multiple pages are passed, the request may not be

2 Session This is the most commonly used method, the advantage of the session is easy to use, the disadvantage is to occupy the server resources, because each of the sessions means that the server needs to maintain the corresponding customer's conversation information, natural if more users logged in, then will be very occupied server resources. In addition, the session has a disadvantage, the default if you log in after 20 minutes without any action, the server will automatically cancel the conversation, so then you need to log in. Ps. Here makes me think of a thing, a few days ago there is a company let me read a piece of code, in the log in, is to use the session record user login, my GOD, Microsoft knew must be vomiting blood. It has worked hard to provide you with the configuration of the web.config <deny user= "*"/> To this one configuration, you do not, still use the session of the ASP era, it is not a waste of MS's painstaking

3 Application This in the ASP era or more commonly used, mainly to store global variables, such as database link information, to the ASP.net era, the use of not much, at least I seem to have never used.

4 Cookies This is my favorite,cookies The biggest feature is maintained by the client, do not occupy the server resources , and you can set the user login, the validity of the cookie, such as a day, so that in a day you do not have to worry about the system to let you log in. Of course cookies have drawbacks, that is security, because cookies at the client, there are some software can analyze the cookie login information, so you write the contents of the cookie not too sensitive, for example, do not store passwords, and as a security, write a cookie is best to encrypt the content.

5) Viewstate ASP. NET new, viewstate easy to use, the disadvantage is only able to use on the same page, in asp.net2.0 This problem can use the button postbackurl results.

6 cache Use cache storage data is not much, but it is also a means, in addition, in the use of cache storage dataset, is actually a reference rather than the content of the copy.

One, the current in the ASP.net page transfer value altogether has so several ways:

1. Form submission, <form action= "target.aspx" method = "POST" name = "Form1" > <input name = "param1" value = "1111"/> T;input name = "param2" value = "2222"/> </form> ... form1.submit (); .... This kind of side in the ASP. NET is not valid because of ASP. NET form is always submitted to its own page, if you want to submit to another page, you need special treatment.

2, <a href= "target.aspx?param1=1111&m2=2222" > Link address Transfer </A> receive page: string str = request["param1"]

3, Session sharing Send page: Session ("param1") = "1111"; Press Receive page String str = session ("param1"). ToString ();

4, Application share Send page: Application ("param1") = "1111"; by page: string str = Application ("param1"). ToString (); This method is not commonly used because application is shared across an application domain, and all users can change and set their values, so only use counters and so on where global variables are needed.

5. Cookies

6, Response.Redirect () way Response.Redirect ("target.aspx?param1=1111&m2=2222") receive page: string str = request["param1" ]

7, Server.Transfer () way. Server.Transfer ("target.aspx?param1=1111&m2=2222") receive 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.