http request state holding four methods

The cookie
the cookie: It sounds great on the Asian sub-high, actually he is just a piece of text, plain text. In the client's browser to store memory or disk inside. And each interface will have its own cookie, it is the main storage sites and related text strings. The main mode of existence to key-value pairs.
What is the principle cookie use is it?

 

cookie storage location and set the expiration time

If we specify the expiration time of the cookie, then the storage word ah client's disk above, if we do not have the cookie expiration date is specified, then stored in the client browser's memory of them.
Of course, if you set an expiration time, the cookie be processed in accordance with the failure you set, when you do not set an expiration time, it will expire after the browser session

 

When is it appropriate to use cookie do?

 

Shopping cart, user Id and so on.
Example: We are in the user login page will add a cookie to store a user name:

Response.Cookies [ "userid"] Value = "123456";.

And then obtain the another page in user Id:

. id = Request.Cookies [ "userid" ] Value;

of course, can also be provided in addition to these cookie expiration time, and inter-like.

Then we can store unlimited cookie do?

Most browsers maximum cookie 4K, so we will only use identifiers such as cookie store small amounts of data or stored user ID. Most browsers store up a website created 20 cookie, if the view to create more, the old will be deleted, the total number of cookie, some browsers will make all sites absolute limit, usually 300. And the value of cookie store is actually unsafe.

 

The Session
session: is a server protection mechanism, and various types of data can be stored in the session, the data is in the open end of the service among a block of memory, this memory is stored in session. session cookie is required before they can help achieve the desired purpose of identity preservation of
the principle session to use:

all have their own session storage of a sessionid, but also to distinguish which user's session variables, back to the server at the time of the visit by the user's browser.
The following example of this is achieved through the session cookie, of course, when the browser does not support cookie, you can use URL rewriting to achieve.

URL rewriting with the above principle difference is that, when performing the response redirect, sessionid server is directly appended to the URL path.

 

session expiration time set

Session default expiration time is 20min, the expiration time for the sliding expiration time. The properties can be modified by the Timeout Session.
When the browser is closed and less than the expiration time, SessionId will not (because seesionid cookie is sent to the browser, and not specified expiration time, the browser hurdle, then the cookie will be deleted, but also no natural sessionId a), but there is still the memory of the data, but the same can not get no SessionId value of Session. Finally, 20 minutes after the server will delete the contents of the Session

 

Hidden Field
What is the hidden fields it?
In fact, in short, I set up a hidden control in which a page, the user can not see. We insert a hidden field in the form dyed back to collect or send information, so that the form is processed can be used. When the browser click to submit the form, and then sent along a hidden field inside information to the server.

Detailed specific role

URL rewriting
URL rewriting is the first to get into the process of a re-written website then it can be handled another URL URL request. For example, if the incoming URL through a browser is "UserProfile.aspx? ID = 1" then it can be re-written as "UserProfile / 1.aspx", so the URL, the URL of this site may be better the reading. Under normal circumstances, if the browser does not support cookie, use this method. For example, we often use the paging URL rewriting is a reflection

 


----------------
Disclaimer: This article is CSDN blogger original article "make_1998", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/make_1998/article/details/103757846

Guess you like

Origin www.cnblogs.com/LQZ888/p/12125738.html