ASP. Common built-in objects: Response objects, request objects, session objects, server objects, application objects
1.Response objects:
(1) To output information to the browser
Common methods are: The Response.Write () method, for example: Response.Write ("Hello"); Response.Write ("<b> Current time is:</b>" +datetime.now);
(2) Use the Response.Redirect () method to redirect the page (that is, the page jumps)---similar to hyperlinks
Example: Response.Redirect ("path")
Sometimes you can also transfer the parameters at the same time as the jump page: Respose.redirect ("Hello.aspx? Name= "+textbox1.text);
(3) Use the Response.WriteFile () method to output a text file to the browser.
2.Request objects--get information from a browser's request to the server, there are three common methods: Request.Form, request, Request.QueryString
(1) request.form--receive form data (POST method)
Used to collect request data submitted using the Post method in a form, the data must be extracted on the server side, and the POST request must be expressed by Form form-----POST method: request.form["variable name"]
(2) request.quertstring--receive form data (GET method)
Used to receive data submitted using the Get method, but the way to submit the data is not very secure, because he will be in the browser address bar URL? The submitted data information is displayed later
For example, the display form: "Http://localhost:1404/FormFirst/Default.aspx?UserName=" 111 "&password=" 222 ""
Get method: request.quertstring["variable name"]
Note: The request.quertstring["variable name" method can also receive values passed over a hyperlink.
(3) ServerVariable Collection
Used to get environment variables, mainly includes the server side and client side of the various system Information--request.servervariable["parameter type"]
parameter types for client information:
Http_user_agent: Get the version of the client browser
REMOTE_ADDR: Gets the IP address of the client browser
Http_accept_language: Get the language used by the client browser
Request_method: How to get the request
Content_length: Gets the total number of characters for the content of the request information
Content_Type: Gets the type of request information
query_siring: Get URL Extensions
Gateway_interface: Get Gateway Interface
Server-side parameter types:
LOCAL_ADDR: Get the IP address of the server
SERVER_NAME: Gets the host name of the server
Path_info: Gets the virtual directory of the currently executing program
Path_translated: Gets the absolute path of the currently executing program
Script_name: Gets the file name (including path) of the current program
Server_port: Gets the port on which the server receives the request
(4) Collection of cookies---store information about clients
A. For sharing data, its shared data is stored in the client system disk: Documents and settings\adminastrator\cookies, mainly to store client-related information, such as numbers, strings, dates, etc. Each browser has its own cookies. It is commonly used to transfer data between different browser pages on the same computer for data sharing purposes.
B. In asp,php, if the client prohibits the writing of cookies, it can cause the program to not be able to use cookies, but in ASP. NET, we can write cookies in any case by setting the Web. config file:
<sessionstate cookieless="true" regenerateexpiredsessionid="true " " />
C.cookie format of writing data
response.cookies["cookie name"]. Value= the data to write
response.cookies["The index number of the cookie"]. Value= the data index number to write starts from 0
D.cookie How to read data
Cookiesvalue=request. ["Cookie name"]. Value;
cookiesvalue=request.cookies["The index number of the cookie"]. Value
E. Removing cookies from cookies
Response.Cookies.Remove ("The name of the cookie to be removed");
Response.Cookies.Clear (); Remove All Cookies
The F.cookie object is life-cycle, the default time is 20 minutes, and if the time exceeds 20 minutes, the de data in the write cookie is automatically emptied.
But we can also set the time-out:
3.Session objects--the effect of quite far global variables
The original page design:
session["Name"]= "Hello";
Response.Redirect ("*.aspx");
Target page receives data
String name=session["Name"];
4.Server objects--provides methods and properties for accessing the server
(1) Server.MapPath ("path")--get the physical path of the current file
(2) for string encoding:
server.urlencode--encoding
server.undecode--decoding
5.Cookies
Asp. NET common built-in objects