Asp.net uses an object-oriented programming environment. Each function file is a series of classes. Creating an Asp.net webpage is to create a new class.
I. How is a class created?
The webpage type is ASP. showpagetype_aspx is used to set ". "is replaced with" _ ", and the base class is system. web. UI. page, which defines most of the features used for requests.
By default, each aspx webpage is derived from the base page class.
Example 1: Use the GetType () method to print the webpage type. The basetype property displays its base class.
<body>
The running result is as follows:
I learned that Asp.net will always convert to a class. Adding new functions to a webpage is like adding new functional methods to the class. Next we will learn about common objects in Asp.net.
2. Objects
1, response
(Inherited from system. Web. httpresponse)
Purpose: send information to the client and control the sending process.
Instance: dynamically create the content displayed on the web page in the browser, change the HTTP title name, and redirect the client to the specified page.
Common attributes are shown in the following table:
Response Method
|
Description |
| Write () |
Output data to the client |
| Redirect () |
Guide the client browser to the new web page |
| Binarywrite () |
Output binary data to the client |
| Clear () |
Clear all HTML pages in the buffer (buffer = true) |
| End () |
Process ASP program termination |
| Flush () |
Send data in the buffer immediately (buffer = true) |
2, request
(Inherited from system. Web. httprequest)
Purpose: Obtain information submitted by the user in a web form or URL parameters, and obtain user-side information.
Instance: obtains the IP address of the client and the browser version.
Common attributes are shown in the following table:
Request Method
|
Description |
| Binaryread () |
Read data transmitted by the client using post in binary mode |
Set
|
Description |
| Querystring |
Obtain the query string submitted by the user in the URL string |
| Form |
Obtain data submitted by a user in a web form |
| Cookies |
Obtain the cookie string information in the client browser |
| Servervariables |
Get server environment variable information |
| Clientcertificate |
Obtain the authentication information of the client browser |
| Browser |
Obtain client browser Information |
3, Server
(Inherited from system. Web. httpserverutility)
Purpose: Configure the server environment, create COM objects and scripting components, and provide server access interfaces.
Attribute
|
Description |
| Scripttimeout |
Set the maximum execution time of the script file (90 s by default) |
Method
|
Description |
| Createobject () |
Create ActiveX components, applications, or Script objects registered to the server |
| Htmlencode () |
Convert string to HTML format and Output |
| Htmldecode () |
Contrary to htmlencode, restore the original string |
| Urlencode () |
Encode and output a string into a URL |
| Urldecode () |
Restore original string |
| Mappath () |
Convert a path to a physical path |
| Execute () |
Stop executing the current page, go to the new page for execution, and return to the original page after execution. |
| Transfer () |
Stop executing the current page, go to the new page, and do not return to the original page |
4. Session
(Inherited from system. Web. sessionstate)
Purpose: Store Users' private information on the server.
Attribute
|
Description
|
Sessionid
|
Stores the user's sessionid, a long integer, automatically generated by the session, with uniqueness
|
Timeout
|
Set the session Validity Period
|
Method
|
Description
|
Abandon ()
|
Clear Session Object
|
Event
|
Description |
Session_onstart
|
Start event. Each time a session object is generated, the event is activated. |
| Session_onend |
End event. This event is activated when the session object is terminated or becomes invalid. |
5. Application
(Inherited from system. Web. httpapplication)
Purpose: Save the public information of all users on the server.
Method
|
Description |
| Lock |
Lock Application Object |
| Unlock |
Unlock |
Event
|
Description |
| Application_onstart |
Start event. It is activated when the application object starts. |
| Application_onend |
End event. It is activated when the application object ends. |
Session and Application Instances
Protected void page_load (Object sender, eventargs e) {// application instance, display the number of times the page is accessed application. unlock (); application ["count"] = convert. toint32 (application ["count"]) + 1; application. lock (); response. write ("you are the nth" + convert. tostring (application ["count"]) + "guest");} protected void button#click (Object sender, eventargs e) {// session instance, read input information session ["name"] = textbox1.text; response. write ("You entered:" + session ["name"]);}