Who should read this article on the Web?
You should read this if you are interested in the following questions but cannot answer them exactly.
What's 1.Session?
What's 2.Cookie?
3. Does cookies,session still work if it's completely disabled?
4. Why do some Web sites log on once and then no longer login?
Does the session in 5.ASP depend on cookies?
Does the session in 6.JSP depend on cookies?
7.ASP. NET in the session is what is going on?
The following is a detailed account of the maintenance of session state, after which you should be able to answer some of the above questions.
The origin of 1.Session and cookies
Here I do not distinguish between cookies and cookies, it's just a plural form. We all know that HTTP is a stateless protocol, that is, each request is separate, the server does not know whether the two request is the same person, if our content is completely open, that is, all the content can see ( such as Sina's news), this kind of situation is not necessary to know whether two requests are the same. But most of the time we don't want this, and we want to be able to visit only after the member has logged in (almost all forums). and others don't allow them to ask, Then you have to know that each request is not the same person, this is the session, that is, a conversation, and this is based on cookies, cookies are the most Netscape company, also called cookies.
The server maintains a session for each request and has a unique sessionid. If the client does not disable cookies, the first time the customer requests this ID will be written to the client's hard disk (not believed?) look at the folder C:\Documents and Settings \username\local settings\temporary The cookie file under Internet files is a text file. You will add this ID value each time you request it, The server side can tell if the same request is being made. If you don't believe it, you can do a test like this:
1. Choose a website (preferably ASP, such as a forum) where you want to log in with your username.
2. Log in first, make sure you can log in, and then turn off the browser.
3. Choose the Internet option (ie property page), select the Hide tab, set the settings to the highest, OK.
4. Re-open IE, login to the site you have just logged in, how not to go up.
2.Session Relationship to Cookies
Currently, there are only two ways to maintain session state
The first: cookies, the most common, more than 95% of the session is the credit of cookies.
The second: URL rewrite, the SessionID appended to the URL, JSP implemented but not much.
If you've ever used a session, you might be surprised: we usually maintain conversations with sessions.
The answer is simple: both of the above are pathways, and the session is our goal. A word summarizing the relationship between session and Cookie: Cookies are the most common way to maintain a session.
3.Cookie Expiration and Session timeout
You can set your own cookie expiration (which is actually set by the server), and if you set it to expire,
There will be no need to land again, if this machine is you can use this set completely, otherwise
It's best not to set this up. If you don't respond for a long time, or if you don't have a new request, the session is possible.
Expired, you may encounter such a situation: clearly already logged in, after a while back but said I did not log in
Prompts to log on again. This is because the session expires, the server can set the expiration time.
4. Disabling cookies How to implement a session
What happens if the client completely disables cookies:
For ASP, the session cannot be traced, which means that each request is treated as a new request.
For JSPs, you can implement a session by overriding the URL, Session.encodeurl (String path)
Session.encodeurl ("index.jsp") =index.jsp;jsessionid=431d980051204fc8dc3
Bf75840f7af71
You can see that the SessionID in the back is not included in the QueryString (after?)
For ASP.net also support rewrite URLs, learn JSP, but JSP not all webserver support rewrite URL
5.QueryString and Hiddenform
You may think that they can also maintain the conversation, but in fact it is not possible, they can only pass parameters. However, the server event model in asp.net is widely used hidden to represent the control's ViewState (this is also asp.net than the asp,jsp advanced Place, is a new technology)
Why can they only pass parameters and not implement sessions? The approximate process is this:
The server receives a request and generates a new session if SessionID is not obtained. Maybe you think this will keep the session url?sessionid=234234234234.
This is a myth because the server is already in a new session, only to get the ID number of the last session.
The difference between 6.QueryString and Hiddenform
QueryString is the QueryString after the question mark in the URL. The general browser restricts the URL to 255 characters so there is no way to pass a large amount of data, the method must be get. Hiddenform is the form data, which can be either get or post (General post)
7. Misunderstanding
I saw someone say in the forum that you can build a session on your Web server and then link to someone else's program to pass validation. The session only works in the same application, so the idea is futile, but if your program is in the same application (for example, some personal homepage space is possible) you can do so.
8. digression
Cookies are exploited because after the client completely disables the cookie, a session is generated each time the server requests it. If the session timeout is 15 minutes, we are constantly requesting the server to generate a large number of sessions in 15 minutes by completely disabling the cookie, implementing a Dos attack ( The premise is that a large number of requests and servers do not filter)
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