. Net built-in object,. net built-in

Source: Internet
Author: User

. Net built-in object,. net built-in

. Net beginners. If you have any errors, please correct them. Common progress

 

Response output data

 

The Reponse object and Request object constitute a pair of objects for sending and receiving data.

Send message: Reponse. Write ("string"); the most common method of Reponse object is Write, used to send information to the browser. The string output using the Write method will be interpreted by the browser in HTML syntax.

Redirection: Reponse. Redirect (URL ):

Buffer processing: Reponse. BufferOutput = true; clear the buffer content. The output is temporarily stored in the server buffer, and the program execution ends or the Flush or End command is received before being output to the client.

Enable buffer Reponse. Flush ();

Buffer Reponse. ClearCountent ();

End the program: Reponse. End ();

 

Request receiving data

 

Get form data:

<Form action = "form submission address" method = "GET/POST">

When a form is submitted in get mode, the data is appended to the URL. Http: // localhost/example. asps? Xx = value1 & xx = value2

In this case, use Requeat. QueryString ["xx"]; To obtain form data.

If the submission method is post, Request. Form ["xx"]; is used to obtain Form data.

You can use request. params ["xx"] to obtain data for any form of submission.

 

Obtain the server environment variables: Reponse. Write ("server NAME or ip" + request. ServerVarables ["sever name "]);

 

Obtain client Browser capability information: Reponse. Write ("client operating system" + request. Browser. platform );

 

Obtain the client Cookie: the cookie is the information stored on the client. It can only store strings. When the browser accesses the Web server, the server uses the Cookie set of the Reponse object to write information to the client's single Cookie, then, the Cookie information is retrieved through the Cookies attribute of the Reponse object.

HttpCookie cookie = new HttpCookie ("cookieName"); instantiate an object

Cookie ["username"] = "xxx"; Value assignment

Response. Cookies. Add (cookie );

Cookie. Expires = DateTime. Now. AddDays (1); add expiration time


If (Request. Cookies ["username"] = null) {judge whether the cookie exists

Do something}

 

Sever Server Object

 

HTML Decoding and encoding: Sever. HtmlEncode (string); encoding Sever. HtmlDecode (string); Decoding

Path conversion: Sever. Mappath ("/"); returns the actual path name of the virtual directory.

Execution of the specified program: Execute is similar to the process call in its advanced language. It transfers the program to the specified program. After the program ends, the process returns the breakpoint of the original program for further execution, transfer terminates the execution of the current program and transfers it to the specified program.

Server. Execute ("xxx. aspx ");

Server. Transfer ("xxx. aspx ");

 

Application collection object (Application Assembly storage)

 

The Application object is derived from the HttpApplicationState class. A single instance of the HttpApplicationState class is created when the client requests any URL resources from a specific ASP. NET Application virtual directory for the first time.

 

OnStart event: triggered when the first ASP. NET program in a virtual directory is executed.

OnEnd event: triggered when the entire application is stopped (usually when the server is restarted, shut down, or IIS is stopped ).

OnBeginRequest event: This event occurs when every ASP. NET request is sent. That is, each time the client accesses a program, it is triggered.

OnEndRequest event: triggered when ASP. NET program ends.

 

Application. Set ("cnt", 0); change the value of the variable named cnt to 0

Application. Lock (); Lock

Application. UnLock (); UnLock

 

Session Object (server storage)

 

OnStart event: when a user accesses an ASP. NET application for the first time, a Session object is created and this event is triggered.

OnEnd event: this event is usually used to process session termination. This event is triggered only when the session state mode is set to Inproc when data is written to a file or database.

 

Session status mode configuration: <configuration>

<System. web>

<SessionState mode = "Off | Inproc | StateServer | SQLSever | Custom"/>

</System. web>

...

</Configuration>

 

Inproc: session data will be stored in the internal cache of HttpRuntime, and data will be lost after the application is restarted.

StateServer: exists in aspnet_state.exe

SQLSever: stored in SQL Server

 

Optimizing Session performance: ASP. NET allows the @ page command EnbleSessionState attribute to clearly describe what Session objects are required on the page.

EnbleSessionState = "true"; read/write access

EnbleSessionState = "False"; no access required

EnbleSessionState = "ReadOnly"; read-only access

 

Page Object

 

Init event: triggered every time a request is sent. It is triggered before Load.

Load event: triggered every request

 

If (! Page. IsPostBack) {// if not loaded for the first time

// Do something}

 

Reprinted please contact

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.