All Web programs are stateless.
Cause: The HTTP transport protocol they use is itself a stateless protocol.
Performance: Each page returned to the customer is unrelated to the previous or subsequent page, unable to access the data on the previous page, or sending data for subsequent pages.
Workaround: Data that is specifically stored on the server side or client by using several objects to store the relevant state.
State objects stored on the service side
Session:
Each stand-alone browser creates a separate session, not a single computer session.
The data stored by the session is shared in the current session.
Session will be released automatically within 20 minutes if there are no sessions.
Grammar:
1. Save value by Session: session["key Name"] = value; Value, which is not just a string, it can be an object.
2. Value from Session: type variable name = (cast type name) session["key Name"]
3. Determine if a value exists in the session
4. Release session
Release a session:session["key name"] = NULL;
Releases all the Session:Session.Clear () in the session;
Automatic release: 20 minutes
Case:
1. Login: Prevent bypassing the login interface.
2. Log in: Remember the user name. Show "Welcome you: Username" on each interface
Application
All sessions share a application space, and anyone who changes the content in the applciation will find it changed.
The data in the application is not automatically freed.
1. Application value: application["key Name"] = value; Value, which is not just a string, it can be an object.
2. Value from application: Type variable name = (cast type name) application["key Name"]
3. Determine if a value exists in the application
if (application["key Name"] = = null)
{
}
4. Release application:application["key name"] = NULL;
State objects stored on the client (on the hard disk):
Cookies
Stored on the client's memory or hard disk.
A temporary cookie is present in the browser memory. Persistent cookies are found in the browser-related cookie directory on the hard disk.
Set cookies
response.cookies["key Name"]. Expires = Expiration time.
response.cookies["key Name"]. Value = values.
Read cookies
string s = request.cookies["key Name"]. ToString ();
Will write a temporary cookie, a persistent cookie, a cookie will be read, and a cookie will be deleted.
Log in with a cookie
webform--Second lecture