ASP. NET learning notes 1: parameter passing summary on the ASP. NET page

Source: Internet
Author: User

ASP. NET page parameter passing Summary

 

1. querystring []

Advantage: it is easy to use and highly efficient to transmit numbers and text values when security requirements are not high.

Disadvantage: the security is not high, the parameter value is directly exposed in the URL, the transfer size is limited, and the object cannot be transferred.

Usage: Construct a URL in page A: String url = "B. aspx? Id = 1 & name = 'hangsan' "response. Redirect (URL );

Accept string id = request. querystring ["ID"] On page B;

2. Session

Advantage: simple to use, not only can pass simple data types, but also can pass objects. There is no limit on the data size.

Disadvantage: storing large amounts of data will consume a lot of server resources.

Usage: on pageCodeMedium session ["name"] = "James"; string name = session ["name"] On page B;

3. Application

Advantage: simple to use, consume less server resources, not only can transmit simple data, but also can transmit objects, the size of data is not limited.

Disadvantage: as a global variable, it is prone to misoperations.

Usage: Same as session.

4. Cookie

Advantage: it is easy to use and is a very common method to maintain the user status. It is stored in the client browser and does not occupy server resources.

Disadvantage: the client has a time limit and is out of date. Only string values can be saved.

Usage: stored value: httpcookie cookie = new httpcookie ("mycookie", "This is Cookie value ");

Response. Cookies. Add (cookie );

Value: string value = request. Cookies ["mycookie"]. value;

 

5. server. Transfer

When server. Transfer is called, the current ASPX page is terminated and the execution process is transferred to the new page. However, the response stream created on the previous page is used.

Compare server. Transfer and response. Redirect:

1. server. Transfer is completed on the server, so the URL address in the browser on the client will not be changed to the new page address to jump. Response. redriect is completed by the client. When a new page Processing request is submitted to the server, the client URL will change. Therefore, server. Transfer reduces the number of requests sent from the client to the server.

2. server. Transfer can only jump to the page specified by the local virtual directory, that is, the page in the project, while response. Redirect is very flexible and can jump to any URL address.

3. server. Transfer can pass values of the previous page to the new page. response. Redirect can only use parameters in the URL.

 

Advantage: Direct server-side redirection is easy to use and reduces client-side requests to the server. Data values of various types and page control values can be passed.

Disadvantage: the address in the browser on the client remains unchanged, which may lead to unexpected situations, such as the slice URL path...

Usage: Server. Transfer ("B. aspx", false) on page );

On page B, you can obtain the object A = (a) context. handler; this is a object that can be used to obtain the value of the previous page, or directly use context. items ["itemname.

Note: You can use this method to obtain the value of the previous page only when loading for the first time. It cannot be obtained in the future PostBack. Therefore, the value method should be placed in if (!) of page_load (! Ispostback.

 

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.