Summary of querystring and page transfer value in ASP. NET

Source: Internet
Author: User
First, add the deletion of the session:

Remove individual: Session. Remove ("AA ");

Clear all: Session. Clear (); (usually used for logout)

 

Querystring:

If a problem occurs when uploading Chinese characters, the solution is as follows:

Encoding Problems:

<Globalization requestencoding = "gb2312" responseencoding = "gb2312"/>

Another method is to first use querystring to encode Chinese characters: Server. urlencode (Chinese character). tostring ();
For example: http: // localhost/test. aspx? Lanmu = server. urlencode (Chinese character). tostring ()

 

Basic usage of querystring in ASP. NET:

Sender:

String querystr = "XXXXX ";

Response. Redirect ("text. aspx? A = "+ querystr );

Acceptor:

Request. querystring ["A"];

 

Main features of querystring:

It is simple and quick, but the passed value is displayed on the address bar of the browser. For security reasons, it is required (if it is Chinese, it is encoded, and the value is reversed ).

At the same time, querystring cannot pass objects. As the name suggests, it passes string strings. Therefore, you can consider using querystring when passing values that do not have high security requirements or short strings.

 


Encoding of querystringDifferences between server. urlencode and httputility. urldecode:

Server. urlencode is encoded according to the encoding method set by the local program, while httputility. urlencode is encoded in. Net UTF-8 format by default.

 

 


Response. Redirect and server. Transfer

Request Process:
1) browser aspx file request ---> server execution ---> response. Redirect statement-> the server sends the address following response. Redirect to the client browser ---> the browser requests a new address.
2) browser aspx file request-> server execution-> server. Transfer statements-> server redirection to new files
You can see that server. Transfer is less than response. Redirect in the process of sending back from the server and re-requesting from the client.
Jump object:
1) response. Redirect can switch to any existing webpage.
2) server. Transfer can only switch to webpages in the same directory or subdirectory.
Data Confidentiality:
1. After response. Redirect, The address will change to the page address after the jump.
2. The address remains unchanged after server. Transfer, hiding the address of the new web page and the parameter values attached to the address. Data Confidentiality.
Transmitted data volume (parameters attached to the URL ):
1. The data that response. Redirect can pass is limited to 2 kb (that is, the maximum length of the address in the address bar.
2. When the transmitted data exceeds 2 kb, you must use server. Transfer.

 

Summary of page value passing:

Client

1. query the string querystring-use the URL to exchange data between the client and the server
2. Hidden form field hidden-set and read data in the form field
3. Cookie --- data stored on the customer's browser
4. View status viewstate --- save page-related data

Server:

5. Application application-this data can be used by all users throughout the application lifecycle.
6. Session session --- this data is in contact with every user
7. Saved status context --- this data exists in a single request
8. cache --- this data is similar to the application
9. Other physical data storage media, such as databases, TXT texts, and XML files
10. Use the server. Transfer Method

 

Describes several common methods for passing parameters between pages in. NET and their advantages and disadvantages.
Querystring transmits one or more values with low security requirements or simple structure. However, this method cannot be used to pass arrays or objects.
Session (viewstate) is simple, but it is easy to lose and act on individual users. Excessive storage will result in the depletion of server memory resources.
The scope of the Application object is global, that is, it is valid for all users. Its common methods are lock and unlock.
The cookie is simple, but may not be supported. The cookie may be forged and stored on the client, while the session is stored on the server. In addition, cookies must be used in combination with ASP. NET built-in object requests.
Input tType = "hidden" is simple and may be forged
The URL parameter is simple and displayed in the address bar with a limited length.
Server. Transfer directs the process from the current page to another page. The new page uses the response stream of the previous page.
The database is stable and secure, but its performance is relatively weak.

 

What is viewstate? What does it do?

Viewstate is used to save the page status, that is, after submission, we can also see that the content in the text box is the credit of viewstate storage.
Viewstate only maintains the status of the current page. Different pages cannot be shared. Session is acceptable.
Viewstate can be understood as a hidden control.

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.