. NET beginners, there is a mistake to welcome correct. We make progress together.
Response output data
The Reponse object and the request object compose a pair of objects that are sent to accept data.
Send message: Reponse.write ("string"); The most common method for Reponse objects is write, which is used to send information to the browser. Strings that are output using the Write method are interpreted by the browser in HTML syntax.
Redirect: Reponse.redirect (URL):
buffer processing: Reponse.bufferoutput = true; clears the buffer contents. The output is temporarily stored in the server buffer, the program execution ends or the flush or end instruction is received and then output to the client.
Enable buffering Reponse.flush ();
Emit buffer reponse.clearcountent ();
End program run: Reponse.end ();
Request to receive data
Get the form data:
<form action= "form submission Address" method= "Get/post" >
When a form is submitted in a Get mode, the data is appended to the URL. Http://localhost/example.asps?xx=value1&xx=value2
At this time, use requeat.querystring["xx"]; To get the form data.
If the submission method is post then use request.form["XX"]; To get the form data.
You can use request.params["XX" to obtain data regardless of the form you submit.
Gets the server environment variable: reponse.write ("Server name or IP" +request. servervarables["SEVER NAME"]);
Gets the client browser capability information: Reponse.write ("Client operating system" +request. Browser.platform);
Get client Cookie:cookie is the information stored in the client, can only store strings, when the browser accesses the Web server, the server uses the Reponse object's cookie collection to write the information to the customer single cookie, The cookie information is then retrieved through the Reponse object's Cookies property.
HttpCookie cookie = new HttpCookie ("CookieName"); Instantiating an Object
cookie["username"] = "xxx"; Assign value
RESPONSE.COOKIES.ADD (cookie);
Cookies. Expires = DateTime.Now.AddDays (1); Add an Expiration time
if (request.cookies["username"]==null) {determine if the cookie exists
Do something}
Sever Server Objects
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-specific program: Execute is similar to the procedure call in its high-level language, the program is transferred to the specified program, the process returns to the original program after the break point continues execution, and transfer terminates the execution of the current program, to go to execute the specified program.
Server.Execute ("xxx.aspx");
Server.Transfer ("xxx.aspx");
Application Collection objects (application set storage)
The Application object is derived from the HttpApplicationState class, and a single instance of the HttpApplicationState class is created the first time the client requests any URL resource from a particular ASP.
OnStart event: Triggered when the first ASP. NET program executes in a virtual directory.
OnEnd event: Triggered when the entire application is stopped (usually when the server is restarted, shutdown, or when IIS is stopped).
OnBeginRequest event: Occurs when each ASP. NET is requested, that is, every time the client accesses a program, it fires once.
Onendrequest event: Triggered at the end of the ASP.
Application.set ("CNT", 0); Change the value of the variable named CNT to 0
Application.Lock (); lock
Application.UnLock (); unlock
Session sessions object (server storage)
OnStart event: When the user first accesses an ASP. NET application, the session object is created and the event is triggered.
OnEnd Event: This event is typically used for session-end processing, such as writing data to a file or database, which is raised when the reply-to state mode is set to InProc.
Configuration of Session-state mode:<configuration>
<system.web>
<sessionstate mode= "off| inproc| stateserver| sqlsever| Custom "/>
</system.web>
...
</configuration>
Inproc: Session data will be stored in httpruntime's internal cache, and data will be lost when the application is restarted
StateServer: Saved in Aspnet_state.exe
Sqlsever: stored in SQL Server
Optimize session performance: ASP. NET allows the @page directive enblesessionstate attribute to clarify what session object the page needs.
Enblesessionstate= "true"; Read/write access
Enblesessionstate= "False"; no access required
Enblesessionstate= "ReadOnly"; read-only access
Page Web Object
Init event: Triggered on every request, before load
Load event: Triggered each time a request is taken
if (!page. IsPostBack) {//If not first loaded
Do something}
Reprint please contact
. NET built-in objects