Today, I started to officially learn the key points of Asp.net... every day. I will record them here...
1. built-in objects
1. Request
The request object is an instance of the httprequest class. common attributes are as follows:
Appactionpath: string type. Obtain the root path of the requested resource on the website.
Contentencoding encoding type setting request object Encoding
Cookie set of cookies sent from the httpcookiecollection client to the server
Querystring namevaluescollection collection of the current query string requested
The urlreferrer URI type obtains the page from which the user jumps to the current page.
2. reponse
Charset string type indicates the character set used by the output stream
Contentencoding encoding: Specifies the encoding of the output stream.
Contentlength: the size of the byte of the output stream of the int type.
Contenttype string type http mime type of the output stream
(MIME Introduction: http://baike.baidu.com/view/160611.htm)
Cookie set of cookies sent from the client by the httpcookiecollection type Server
Output textwrite type server's corresponding object character output stream
Redirectlocation string type redirects the current request
Common reponse Methods
Appendcookie adds a cookie to the cookie set of the response object
Clear all content output of the buffer
Close close the connection from the current server to the client
Redirect redirects the current request
End ends the response and sends the output in the buffer to the client.
3. Server
A server object is an object used to obtain server-related information. It is an instance of the httpserverutility class and is a common method.
Void Execute Executes the specified resource, and after the execution, the code on this page is executed
Eliminate the impact of string htmldecode on special string Encoding
Encode the special string of the string htmlencode object
String mappath obtains the physical path of the specified relative path on the server.
Void transfer stops executing the current program and executes the specified resource
String urldecoder decodes the path string
String urlencode encode the path string
Note: The connection method starting with HTML is for HTML code encoding and decoding, while the method starting with URL is for URL address encoding and decoding.
4. Session
The Session object is used to save information related to a specific user. It is an instance of the httpsessionstate class. session data is stored on the server side and a session is created when the client needs it, the session is destroyed when the client does not need it so that it does not occupy the server memory.
Session features
The session data is stored on the server.
The session can store any data type.
The default life cycle of a session is 20 minutes. You can manually set a shorter time in the future.
Eg:
Set session: session ["username"] = "duzouzhe ";
Get session: String username = (string) session ["username"];
5. Cookie
The cookie object is used to keep data related to a specific user. It is an httpcookie instance. Unlike Session, the cookie is stored on the client rather than on the server, each request sent by the client sends the cookie together to the server. Each request sent by the server to the corresponding client resends the cookie and sends it to the client for storage.
Cookie features
The data in the cookie is stored on the client.
The cookie can only store string-type data. If you need to save other types of data in the cookie, you need to convert it to string-type data and save
The cookie also has a default life cycle. The maximum value is 50 years.
Eg:
Httpcookie cookie = request. Cookie ["name"];
If (cookie = NULL)
{
Cookie = new httpcookie ("name", "duzouzhe ");
Cookie. expires = datetime. Now. adddays (10 );
Response. cookier. Add (cookie );
}
Else
{
Response. Write ("Cookie:" + Cookie. value );
Cookie. expires = datetime. Now. addyears (-1 );
Reponse. Cookies. Add (cookie );
}
6. Application
Application is an instance of the httpapplicationstate class. the data types stored by the application and session are the same as those stored in the session. all data of the object type is stored on the server. the difference is that the data in the application can be set or obtained by all users on the website, and there is no time limit for the data stored in the application, unless we manually delete the data or restart the server.
Session, Cookie and Application Comparison
Session-specific users are stored on the server. If the storage type is object, you can set the lifecycle by yourself.
COOKIE: The storage type of a user stored on the client is string. You can set the lifecycle by yourself.
Application all users are stored on the server. If the storage type is object, you can set the lifecycle.