Asp. NET state saving is divided into two kinds: the client save and the server-side save.
These options that use the Client option to store page information without using server resources tend to have the lowest security but the fastest server performance because the requirements for server resources are modest. However, because information must be sent to the client for storage, there are some objective limitations on how much information can be stored in this manner.
The way the client is stored is generally as follows: 4
1 ViewState:
The use of the occasion is: on the same page of multiple requests automatically retain the value, more for the client's some events. , typical use of occasions for: page information reset, landing error count, grid column sorting.
Advantage: Do not use server-side resources for simple, relatively high security: because of hashing and compression, and encoding for Unicode implementations.
Disadvantage: Because viewstate is stored on the page itself, large values cannot be stored. And the value can be seen through the source file, although hashed and compressed, there is still the risk of tampering.
Types that can be stored: String,integer,bool,array,arr aylist,hashtable and other types that can be serialized.
2 HiddenField:
The use of the occasion for: storage of a small number of pages often changed information, and the use of client-side script, a typical use of occasions: the client after a series of authentication to the server-side postback, server-side from the client HiddenField to obtain value, processing. For example: In Leyserhomepage, to delete a product, you need to eject the confirmation form on the client, and then PostBac K back to the server side for the database delete operation when the user confirms that you want to delete it. Store the Product ID that is currently being removed into a hiddenfield, and then execute the Form (0). Submit back to the server side, the server side from the HiddenField to obtain product ID values, database operations.
Advantages: Do not use server resources, wide support, easy to implement
Disadvantage: Security is not high because it is included on the page to send, so you can see his content through the source file. Less storage structure, only support simple data structure such as String,integer,bool,array,arraylis T. And only simple single values are stored on them, and additional coding is required to hold multiple values. There is less storage because it is stored on the page itself, so a larger value cannot be stored. And the large amount of data will be blocked by firewalls and agents. Note: After using HiddenField, you need to post back to the server for processing, and you should use the HTTP posts method instead of the HTTP GET method (access through the URL)
3 Cookies:
The use of occasions for: storage of a small number of pages often changed information, typical use of the occasion: for the landing site to save the login username, for user input to facilitate, there are some user-defined items on the user's personalized settings to save.
Advantages: Do not use server resources, implementation is simple, can configure expiration time.
Disadvantage: size is limited, and the maximum cookie capacity supported by the General browser is 4096 bytes. The client user may be configured to reject cookies. Security: Information that is stored on the client may be modified or acquired by a malicious user, so sensitive information should not be saved. Persistence: The retention period is affected by the configuration of the client.
Cookies are typically used to access personalization of known user-defined content. In most of these cases, cookies are "identity" rather than "authentication," so it is sufficient to store only a user name, account name, or unique user ID (such as a GUID) in a cookie and use it to access the site's user personalization structure.
4 QueryString:
The simplest way to pass information from one page to another is to use the occasion:
Advantages: Do not use server resources, support a wide range, simple to achieve
Disadvantage: Security, because it is exposed to the user directly in the URL, there is a risk of tampering. Capacity is limited, the average browser has a limit of 255 characters. The query string is a viable option only if the page is requested through its URL. The query string cannot be read from a page that has been submitted to the server.
View state: You need to store a small amount of information for a page that will be sent back to itself. The use of the ViewState property will provide functionality with basic security.
Hidden fields: You need to store a small amount of information for a page that will be sent back to itself or another page, and no higher security is required. (client events) can only use hidden fields on pages that are submitted to the server.
Cookies: A small amount of information needs to be stored on the client and no higher security is required. Personalized
Query string: You can transfer a small amount of information from one page to another without the need for higher security. (page jump) You can use a query string only when you request the same page, or when you request another page through a link.
Server-side storage methods generally have the following 3 kinds:
Server-side options for storing page information tend to be more secure than client options, but they may use more WEB server resources, which can cause scalability problems when the volume of information is high.
1 Application:
Use the occasion: all requests will need some common resources, from the first request after the first acquisition, take out the share, other requests do not waste resources to obtain again. Typical use: A stock market web site can get a lot of financial stock information (perhaps MB of data) from the database every 5 minutes a day, and then cache that information in application state so that all future lookup requests can access that information in the application state. The result is a significant increase in the performance of each request, because incoming requests do not require a roundtrip process across the process, across computers, or from the database.
' First HTTP GET please
If not Me.ispostback Then
"First of all, to determine whether the application has 経
If Application.item ("Database") is nothing Then
"If not, take it from the datacenter.
Dim DS as New DataSet
Ds. READXML (Server.MapPath ("Testdata.xml"))
Dim DV as New DataView (ds. Tables (0))
"After you get it, slow it down to application, and make it easier for you to do HTTP gets, please.
Application.add ("DataBase", DV)
End If
Dim Dv1 as DataView
DV1 = Application.item ("DataBase")
"Save to session to facilitate the current process of HTTP POST please
Session.add ("DataBase", DV1)
End If
Advantages: Easy to implement, global scope.
Disadvantages: Durability, if the server-side process of saving data is forcibly shut down, then the data will be lost, so use application must have a guaranteed policy, and some words on the use, do not have to take their own. Consumes server-side memory.
Note: Because the data in application is common to multiple processes, if you need to update the values, you need to use the following statement to do the exclusive update:
Application.Lock ()
Application.item ("DataBase") = Newdatabase
Application.UnLock ()
2 session:
Use: A separate process used internally to store short-term, sensitive data for individual sessions.
Benefits: Easy to implement, persistent, can be restarted for IIS and worker processes, can be used in multiple processes
Disadvantage: Consumes server-side memory.
3 Database:
Advantages: Security. Capacity. Persistence. Reliability and data integrity. accessibility. Wide support.
Disadvantages: Complex, Performance 0 0 0 (please comment on the article)