ASP. NET page, asp.net page
This is a pen question for an interview with an ocean company last week. During the interview, the interviewer also asked me that although I had prepared for it and answered it at the time, I didn't quite understand it at all. In the past two days, when the evaluation system of the efficient platform was used to pass the value on the page, some related information was found on the Internet.
Common page values include QueryString, Session, Cookies, Application, and Transfer. Next, let's take a look at the working mechanism, interconnectivity, and advantages and disadvantages of various value passing methods.
QueryString value:
QueryString is also called URL-based value transfer. It is a common and simple value transfer method. It Concatenates the data we need to transmit to the connection address and transmits it to the target address.
Advantage: it is easy to pass URL values and supported by all browsers. It is very effective for data transmission of string types.
Disadvantage: The security factor is not high. It completely exposes the data we need to transmit in the address bar. If encryption technology is not used, it is irrational to use URL-based data with high security. This method is required for data types. Generally, only strings can be transmitted. This method is not applicable to the transmission of arrays and objects.
Session value:
Session value transfer is certainly not unfamiliar to everyone. It has something in common with the Application, but also has a difference. It is a global variable with a scope. For example, for an application website, Session can contain information of a single user. Application is a global variable without local restrictions. It can store the information of the entire website, such as the real-time traffic of the website.
Advantage: it is easy to use, not only to transmit data, but also to transmit objects, the size of data is not limited.
Disadvantage: storing a large amount of data in Session variables consumes a lot of server resources and data is easy to lose.
Application Value:
The value transfer method may be rarely heard or used, but I have never used it. We can associate it with the previous Session value. We believe it will be much better understood. It is effective throughout the life cycle of the application, just like global variables, so it can be accessed on any page.
Advantage: it is easy to use and consumes less server resources. It not only transfers data, but also objects. The data size is not limited.
Disadvantage: as a global variable, it is prone to misoperations.
Cookies:
We are no longer familiar with the transfer of Cookies. People who often use computers and mobile phones may find that one of the items is to clear Cookies when cleaning up the garbage. After we clear the Cookies, it is found that the user name and password previously saved by some common websites need to be re-entered. This is the role of Cookies. It is often used to store user-related information on the user's browser, such as our user name and password. When we log on, we choose to save the user name and password, the information will be stored in Cookies. We do not need to enter them manually during next login. Therefore, we need to select whether to clear the garbage as needed. Cookies and sessions are similar in that they are targeted at individual users. However, they are essentially different in that Session is stored on the server, while Cookies are stored on the client.
Advantage: it is easy to use. It is a very effective way to save the user status. storing all information on the client does not put pressure on the server.
Disadvantage: the security is not high, and it is easy to be forged, which brings a certain amount of memory garbage to users.
Transfer value:
Transfer is a relatively advanced method for transferring values. Only Transfer can be regarded as an object-oriented software design method. Use the Transfer method to direct the process from the current page to another page, that is, the redirection we often call. The new page uses the response stream of the previous page, therefore, this method is completely object-oriented.
Advantage: Direct redirection on the server side is easy to use, which reduces client requests to the server and can pass various data types and control values.
Disadvantage: the URL address in the browser on the client does not change. Therefore, some intent errors may occur on the new page. For example, if the original page and the target page are not in the same virtual directory or subdirectory, some images or hyperlinks using relative paths will cause incorrect targeting.
The above are some common ASP. NET page value passing methods I have found on the Internet. I have sorted them out through some of my own understandings. If you have any shortcomings, please criticize and correct them.