Today ran to the library to read books, a lot of things forget, and sometimes job interview can not say, then have time to read
The following is from the "C # and ASP. NET Programming Tutorial" Wang Zhenwu a book to see, write very detailed, sometimes will be used, then moved to this side, sharing, learning; I'm just a porter of knowledge, whoa, KA!
Built-in Object name |
Function description |
Page |
Processing the contents of an ASP. NET page |
Requset |
Get information about the client and the server |
Response |
Sends HTTP-related data and related information to the client |
Server |
Provides a range of web-related programs |
Session |
Storing information about a client session in the server's memory |
Cookies |
Store information about customers and websites on the client side |
Application |
Store information for multiple accesses to the application on the server |
Common Properties for Page objects
IsPostBack: Gets a Boolean value that indicates whether the page was first loaded and accessed, and the first access is false, again to true.
Form: Gets the HTML form of the page.
Validator: Gets the collection of validation controls on the requested page
Common events for Page objects
PreInit: Occurs at the beginning of page initialization
Init: Occurs when a server control is initialized; initialization is the first step in the lifetime of a control
Initcomplite: Occurs when page initialization is complete
Preload: Occurs before the page load event
Load: Occurs when a server control is loaded into a Page object
LoadComplete: Occurs at the end of the load phase of the page life cycle
PreRender: After the control object is loaded, the rendering occurs before the
Unload: Occurs when a server control is unloaded from memory
Dispose: Occurs when a server control is freed from memory
DataBinding: Occurs when a server control is bound to a data source
Asp. NET page execution order is as follows:
- Page initialization, triggering the Page_Init () event
- Load Page view state viewstate;viewstate is used to maintain the state of the control itself and is not accessible by the user
- Loading the page, triggering the Page_Load event
- Events raised by server controls when the page runs
- The page is unloaded from memory. Trigger Page_Unload () event
Common properties of the request object
Form: Get a collection of form variables
QueryString: Gets the collection of HTTP query string variables
ServerVariables: Get a collection of Web server variables
Cookie: Gets the collection of Cooike sent by the client
Browser: Gets or sets information about the client browser feature being requested
Cilentcertificate: Gets the Client Security certificate for the current request
<id= "Form1" runat= "Server" method= "Post" > < ID= "TextBox1" runat= "Server"></ASP : TextBox></form>
Gets the value of the control:
Use form to pass data (POST) request.form["field name"] or requset["field name"];
Use UML to pass data (GET) request.querystring["field name"];
Syntax format for the ServerVariables property
request.servervariables[" environment variable name "]
Common Server environment variables
- All_http: HTTP header content sent to the client browser
- Appl_raw: All raw information transmitted to the client browser
- Appl_md_path:web the relative path of the application
- Appl_physical_path:web the physical path of the application
- Auth_password: Password for customer authentication information
- Content_length: The length of the file sent to the client
- Auth_User: Customer-Authenticated user account information
- Auth_type: Whether users have access to the identity of the protected script
- Content_Type: File types sent to the client
- Gateway_interface: CGI version on server side
- Http_accept_language: Languages allowed on server side
- Http_connection: Server-side Online status
- Http_host: Host name of the server
- Http_user_agent: Cookies used on the server side
- Http_accept_encoding: Allowable encoding for server-side use
- LOCAL_ADDR: Server-side IP address
- LOGON_USER: Client information logged when a user logs on in a Windows NT system
- Query_string: Data passed with a URL
- REMOTE_ADDR: IP address of the client
- Remote_host: Host name of the client
- Request_method: How to transfer Web Form data: Get/post
- Script_name: Relative path and file name of the current ASP. Net file
- SERVER_NAME: Server-side IP address and name
- Server_post: When using HTTP for data requests, the server-side port number used
- SERVER_PROTOCOL: Communication protocols used on the server side
- Server_software: Software, version and name used on the server side
- Relative URLs of URL:ULR
Browser properties commonly used for browser properties
request.browser[" Browser property name "]
- Type: The name and major version number of the client browser (integer)
- Backgroundsounds: Does the client browser support background sound
- Browser: Name of the customer's browser
- Version: The full revision number (integers and decimals) of the customer's browser
- MajorVersion: Major version number of the client browser (integer)
- MinorVersion: Minor version number (decimal) of the customer's browser
- Platform: The name of the platform used by the client
- Frames: Whether the client browser supports HTML frames
- Tables: Whether the client browser supports tabular functions
- Cookie, whether the client browser supports cookies
- Clrversion: the client browser. The version number of the net common language runtime
- Javaapplets: Whether the client browser supports Java applets
- javascript: Does the client browser support JavaScript
- ActiveXControls: Whether the client browser supports ActiveX controls
- Win16: Whether the client browser is a 16-bit Windows-based computer
- WIN32: Whether the client browser is a 32-bit Windows-based computer
ClientCertificate Property
- AllKeys: Gets all keys in the NameValueCollection object
- binarylssuer: Gets or sets the certificate issuer (in binary notation)
- certencoding: Get the encoding for the certificate
- Certificate: Gets a string that contains the binary stream of the entire certificate content
- Cookie: Gets the unique ID of the client certificate (if provided)
- Falgs: A set of identities, Provides information about additional client certificates
- IsPresent: Gets a value that indicates whether the client certificate exists in
- Issuer: A string that contains a list of field values for the certificate issuer information
- IsValid: Gets a value that indicates whether the client certificate is valid
- item: Gets or sets the specified item in the NameValueCollection object
- KeySize: Gets the number of digits of the digital certificate key size
- PublicKey: Gets the public key binary value of the certificate
- secretkeysize: Gets the number of bits of the server certificate key
- SerialNumber: Represents the certificate serial number as a hyphen-delimited hexadecimal ASCII character form
- Serverissuer: Gets the issuer of the server certificate
- serversubject: Gets the recipient of the server certificate
- Subject: Gets the recipient of the client certificate
- Validfrom: Gets the date that the certificate is in effect, which differs depending on the locale
- validuntil: Get the certificate expiration date
void Page_Load (object Sender,eventargs e) { Sysem.Web.HttpClientCertificate HDC= Request.clientcertificate; Label1.Text=HDC. Ispresent.tostring (); // ...... }
Common properties and methods of response objects
Buffer: Gets or sets a value that indicates whether the output is buffered and sent after the entire response has been processed
BufferOutput: Gets or sets a value that indicates whether the output is buffered and sent after the entire page is finished processing
Cache: Gets the Web page's caching policy (Expiration time, privacy, change clause)
Cookies: Get Response cookie Collection
Write (): Output information to the customer's browser
Redirect (): Redirect the client to the new URL
BinaryWrite (): Output binary information
Clear (): Clears all HTTP pages in the buffer
End (): sends all current buffered output to the client, stops execution of the page, and raises the Application_EndRequest event
Flush (): Sends all current buffered output to the client
When the compiler executes to Response.Redirect, the page specified by the method is opened immediately, and the statement after the Response.Redirect method has no chance of execution at all!
For redirect (), only if buffer and BufferOutput are set to true, and if the buffer and BufferOutput properties are false, the server will output the page directly to the client, and after the HTML element has been output, Also want to guide the page to another page display is not allowed!
When Response.Clear () is executed, the contents of the server buffers are all purged, and in the client browser, only the execution results after the statement are visible.
When executing Response.End (), the execution of the program is terminated, the existing contents of the buffer are all output to the browser, and the statement after the End method is not executed.
When Response.Flush () is executed, the entire contents of the buffer are output to the browser, and the buffer is emptied, and the statement after the Flush method can continue execution.
Server Objects Common Properties and Methods server objects are implemented by the System.Web.HttpServerUtility class
ScriptTimeout: Gets or sets the request time-out value (in units of s)
Execute (): The handler that executes the specified virtual path in the context of the current request
Transfer (): Terminates execution of the current page and starts execution of a new page for the current request
MapPath (): Returns the physical path of the virtual path object executing on the Web server
Session Object implemented by the System.Web.SessionState.HttpSessionState class
Timeout property: Gets and sets the allowable time (in min) between requests before the session-state provider terminates the session, which defaults to 20min
Abandon () Method: Clear Session Object
The role is to record the user information in a session; the ASP. NET application maintains a Seesion object for each user, and Seesion objects are often used to store information that needs to be used across pages.
The object type is stored in the Seesion objects and a type conversion is required when the read operation occurs.
session["Key"]=value;
The session object exists in the server's memory and therefore cannot occupy server resources indefinitely. The default validity period is 20min, which can be reset by session.timeout=100;
Cookie Object
It is also used to store user information, except that the session object stores the information in the server's memory, and the cookie stores the user information on the client.
Name: Gets or sets the names of the cookies
Value: Gets or sets the value of the cookie
Expires: Gets or sets the expiration date and time of the cookie
Add (): Add a cookie variable
Clear (): Clears the variables in the cookie collection
Get (): Gets the variable value of a cookie by a variable name or index
GetKey: Gets the variable name of the cookie in the indexed value class
// Create a cookie // There are two ways to create Cooike response.cookie["userName"]. Value="Admin"; response.cookie["userName"]. Expires=datetime.now.adddays (1);
If you do not set the expiration time, cookie information will not be written to the user's hard drive, it will be discarded when the browser is closed, or a cookie can be created as follows:
HttpCookie acookie=NewHttpcoopie ("UserName"); Acookie.value=DateTime.Now.ToString (); Acookie.expries=datetime.now.adddays (1); RESPONSE.COOKIE.ADD (acookie);//Create a multi-valued cookieresponse.cookie["UserInfo"]["UserName"]="Admin"; response.cookie["UserInfo"]["lastvisit"]=DateTime.Now.ToString (); Response.Cookie.Expires=datetime.now.adddays (1);
Read cookies
if(request.cookie["UserName"]!=NULL) Str=server.htmlencode (request.cookie["UserName"]. Value);//multi-valued cookie Reading exampleHttpCookie acookie=request.cookie["UserInfo"];stringusername=acookie.value["UserName"];stringlastvisit=acookie.value["lastvisit"];
Modify Cookies
HttpCookie acookie=request.cookie["userInfo"];acookie.values[ " UserName"]="one_user"; // or ACookie.Value.Set ("userName","one_user " ); Response.appendcookie (acookie);
Delete Cookies
HttpCookie acookie=request.cookie["userInfo"];acookie.values.remove (" userName");
Advantages:
- Configurable expiration rules
- No server resources are required. Cookies are stored on the client and read by the server after sending
- Simplicity. A Cookie is a lightweight, text-based structure that contains simple key-value pairs
- Persistence of data. You can set the maximum duration
Disadvantages
- Size is limited. Most browsers have a cookie size of 4096B, which is now more common for 8192B
- The user is configured to disable. Some users disable the ability to receive cookies on their browsers.
- Potential security risks. Cookies may be manipulated and tampered with, resulting in security risks and application response failures that may depend on cookies
Application Object
The Seesion object stores information in a type of manner, and the Application object also stores the user information in the server.
Different: The Application object is a public variable that allows multiple users to access it, while the session object allows only a specific user to access it.
Syntax: application["ApplicationName"]= variable/constant/string/expression;
Because multiple users are allowed access to the Application object, it is necessary to use lock and unlock to implement synchronous access to public resources.
Application.Lock (); application["ApplicationName"]=app_name; Application.UnLock ()
Dear friends, have you read it carefully? Can not be white to see, solve the following problem
- Explains the differences and linkages between the Clear,end,flush methods of response objects
- Describes the same and different points of the application object of the Session object
- Describe the difference between a cookie object and a Session object
Asp. NET built-in objects (verbose)