In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the method of data transmission between ASP.NET pages". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the method of data transmission between ASP.NET pages".
The Web page is stateless, and the server assumes that each request comes from a different user, so the state of the variable is not retained between successive requests to the same page or when the page jumps. When designing and developing a Web system with ASP.NET, an important problem is how to ensure the correct, safe and efficient transmission of data between pages. Asp.net provides a variety of technologies such as state management to solve the problem of saving and transferring data, so as to discuss various methods and their respective applicable situations to solve this problem under. Net.
I. various methods and analysis of data transmission between ASP.NET pages
1. Use the Querystring method
QueryString is also called a query string, and this method appends the data to be passed to the web page address (URL) for passing. If the page A.aspx jumps to the page B.aspx, you can use the Request.Redirect ("B.aspx? parameter name = parameter value") method, or you can use the hyperlink: after the page jumps, you can use Ruquest ["parameter name"] to receive the parameters in the target page. The advantage of using QuerySting method is that it is simple to implement and does not use server resources; the disadvantage is that the passed value will be displayed on the browser's address bar, there is a risk of tampering, the object cannot be passed, and the query string is feasible only when the page is requested through URL.
two。 Take advantage of hidden domain
Hidden fields are not displayed in the user's browser, but usually add a hidden control to the page, assign the value to the hidden control and submit it to the next page when interacting with the server. A hidden domain can be a repository of any web page-related information stored in a web page.
Use: hidden control .value = value when storing values using hidden fields, and: variable = hidden control .value when taking out and receiving values. The advantage of using hidden fields is that it is easy to implement. Hidden fields are standard HTML controls and do not require complex programming logic. Hidden fields are stored and read on the page without any server resources, and almost all browsers and client devices support forms with hidden fields. The disadvantage is that it has less storage structure, only supports simple data structure, and has less storage, because it is stored in the page itself, so it can not store large values, and a large amount of data will be blocked by firewalls and agents.
3. ViewState
ViewState is a hidden form field managed by the ASP.NET page framework. When ASP.NET executes a page, the ViewState value and all controls on that page are collected and formatted into an encoded string, which is then assigned to the value property of the hidden form field.
Available when passing data using ViewState: ViewState ["variable name"] = numeric value, and when fetching data: variable = ViewState ["variable name"].
The advantages of using ViewState are: automatically retain values among multiple requests for the same page, without server-side resources, and easy to implement; the values in view state are hashed and compressed, and encoded for Unicode implementation, so its security is higher than using hidden fields; the disadvantage is that ViewState is stored in the page itself, so if you store larger values, users may slow down when displaying and sending pages. Although view state stores data in a hash format, it can still be tampered with.
4. Use Cookie
Cookie can pass a small amount of information between pages, which can be stored in the client's text file or in the client's memory. The Cookie method is suitable for storing frequently changed information in a small number of pages, such as saving login user names for logged-in websites, providing convenience for users to enter, and saving user personalization settings on some user-defined projects. Available when using Cookie to pass data: Response.Cookies ["key name"] = key value; take out data with: variable name = Request.Cookies ["key name"].
The advantages of using Cookie are: Cookie is stored on the client side, no server resources are used, the implementation is simple, and the expiration time can be configured. The disadvantage is that the amount of data that can be stored is relatively small, and because Cookie is not supported by all browsers and may be banned or deleted by users, it cannot be used to save critical data. In addition, the form of Cookie is simple plain text, so it is not suitable to save sensitive, unencrypted text in it.
data.
5. Use Application variabl
You can also use the Application variable to transfer values between pages. The Application variable is global and all users share an Application variable. Once defined, it will affect all parts of the program. If you want to use a variable value Application object throughout the application, it will be a * choice. When storing data, add the value to the Application variable: Application ["variable name"] = numerical value; take out the data with: variable = Application ["variable name"]; when you do not need to use the Application, explicitly clear it: Application ["variable name"] = null.
Application advantages: easy to use, global scope. Accessible to all pages in the application. Disadvantages: if the server-side process that stores the data is damaged (such as due to server crash, upgrade or shutdown), then the data will be lost, so you must have a guaranteed strategy to use Application; it takes up the memory of the server, which may affect the performance of the server and the scalability of the application.
6. Use Session variabl
Session objects can be used to store information about specified conversations that need to be maintained, and different clients generate different Session objects. Session is used to store short-term information specific to individual sessions. Session is used in the same way and format as Application.
Advantages: easy to implement, and provide high security and persistence, can deal with IIS restart and worker process restart, can be used in multiple processes. The disadvantage is that it consumes server-side memory. So don't store a lot of information. The most common use of Session is to work with Cookie to provide user identification to Web applications, and Session can also be used in browsers that do not support Cookie. However, using a Cookie-free Session requires placing the session identifier in the query string, and you will also encounter the security issues described in the query string section of this article.
7. Use the static properties of a class
This method uses the static properties of the class to realize the value transfer between two pages. Define a class that contains static attributes; assign the value to be transferred to the static property; in the target page, you can get the value to be passed in the source page through the static property. The advantage is that it is convenient to transfer multiple data, but the disadvantage is that it needs additional programming, increases the workload of programming and occupies the memory of the server.
8. Use Server.Transfer
Transfer the execution process from the current ASPX file to another ASPX page on the same server through the Server.Transfer method, while retaining the form data or query string, by setting the second parameter of the method to True, in * pages with Server.Transfer ("target page name .aspx", true); the target page takes out data with: Ruquest.Form ["control name"] or Ruquest.QueryString ["control name"]. This can also be used in Asp.net2.0, with the following code:
PreviousPage pg1; pg1= (PreviousPage) Context.Handler; Response.Write (pg1.Name)
Note: this code is used to extract the passed value in the target page, Previous- Page is the class name of the original page, Name is the attribute defined on the original page, and the data to be passed is stored in this attribute.
Using this method, you need to write some code to create some properties so that you can access it on another page, and you can access values as object properties on another page, which is particularly useful in the transfer of values between pages. this method is not only concise, but also object-oriented.
9. Cache
Cache has a powerful data manipulation function, storing data in the form of key-value pairs, and you can insert and retrieve data items by specifying keywords. Its dependency-based termination function enables it to accurately control how and timely update and eliminate data in the cache. It can be locked internally and does not need to be serialized using Lock () and Unlock () methods like Application objects. The disadvantage is that the method of use is more complex, improper use will reduce the performance.
2. the value transfer method that can be used in the case of different page jumps.
Case 1: the source page can jump to the target page, and the source page passes the data to the target page
Using a query string to transfer a small amount of information from one page to another and when there are no security issues is a simple and common method; using the Server.Transfer method, you can pass form data or query strings to another page, and you can save the HttpContext of the initial page, which you can use when the target page and the source page are on the same server.
Case 2: the page passes the value to its own page
That is, values are retained among multiple requests to the same page, and the ViewState property provides functionality with basic security. You can also use hidden fields to store a small amount of page information posted back to yourself or to another page, regardless of security concerns.
Case 3: the source page passes a value to the target page, but the source page cannot be directly connected to the target page.
There are several ways, which one depends on the specific situation.
Application: stores global information that is used by multiple users and changes infrequently, so security is not an issue. Don't store a lot of information. Session: stores short-term information specific to individual sessions and requires a high level of security. Do not store large amounts of information in session state. It is important to note that session state objects are created and maintained for the lifetime of each session in the application. In applications that support many users, this can consume a lot of server resources and affect scalability.
Cookie: use when you need to store a small amount of information on the client and there are no security issues. Class to facilitate the transfer of multiple data.
Cache: objects are used for a single user, a group of users, or all users. Data can be saved for multiple requests for a long time and efficiently. The above methods are not only used in case 3, but can be used in both cases, but they can be used as little as possible when it is not necessary, otherwise it will cause a waste of resources or increase the complexity of the program.
Thank you for your reading, these are the contents of "what is the method of data transmission between ASP.NET pages?" after the study of this article, I believe you have a deeper understanding of what is the method of data transmission between ASP.NET pages, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.