I. Overview
ASP. NET provides a complete server-side object model that can be used during running. ASP. NET can access all controls on the page as objects in its environment. The ASP. Net that generates HTML content is usually called a web form by using the control function on the page.
Basically, the status information of controls on the web form (including the information entered in the text box and the options in the drop-down list) is stored in the hidden viewstate field, this field is part of the page generated by the server and sent to the user. Subsequent operations are called sending (PostBack ).
Ii. ASP. NET web forms
● Keep the app_date folder, which contains data files, such as XML files or database files.
● On the ASP. NET page, there is only one server <form> element.
● Runat = "server" indicates that the form will be processed on the server and must be possessed. Otherwise, the form will not perform any operations.
● The <@ % PAGE %> tag on the top defines the page features.
2.1 Process
. Aspx layout (HTML) and ASP. NETCode.
. Aspx. CS is the code used to customize form operations.
Pre-compiled site process:
● ASP. NET processor execution page, determine the object creation to instantiate the Page Object Model.
● Dynamically create a base class, including control members on the page and event handling of the controlProgram(For example, click an event button ).
● The Page code file is combined with this base class to form a complete object model.
● Compile all the code and tell the cache.
● Generate HTML and return it to the user.
2.2. Common System Objects in ASP. NET
Page Object: the method of the page itself.
Request object: encapsulates the details (parameters, attributes, and data) of HTTP requests generated by the client ).
● The querystrings attribute collects the data sent by the GET request.
● The from attribute collects the data sent by the POST request.
● Servervariable (environment variable) set contains the system information of the server and client. Add the property trace = "true" to the page command to trace detailed environment variable information.
● The Params set contains the preceding three methods.
Response object: The response returned to the HTTP client.
● The write () method can output the specified text content.
● The end () method enables the Web server to stop the current program and return results.
● The redirect () method can redirect the page to another page.
Session Object: Share the page information during the session period.
Session ["XXXX"] = value object;
Object = session ["XXXX"];
Cookie object: The cookie object is shared with the client. Corresponds to the httpcookie class.
Response. Cookies ["XXXX"]. value = string variable;
String xxx = request. Cookies ["XXX"]. value;
Application Object: Provides shared information during application running.
Application ["XXXX"] = value object;
Value variable = application ["XXXX"];
Server Object: It only encapsulates some common web server-related methods.
Server. mappath ("~ /"); // Return the physical path of the virtual directory
Server. htmlencode ("XXXX"); // the HTML code is not compiled and output directly on the page.
Server. encode ("XXXXX"); // encode the special characters of the URL address
Server. Execute ("XXXXX"); // The page specified by the execution parameter. After the execution, the page is returned.
Server. Transfer ("XXXX"); // The page specified by the execution parameter, which ends after execution
3. Application configuration
The application is defined as all files in the project and configured by the web. config file.
When an application is created for the first time (when the first HTTP request is received), the application object is created. The application_start event is also triggered to create an httpapplication instance pool. Each input request will receive such an instance and execute the request processing process. Unlike the global application object, After all httpapplication instances complete the task, the application_end event is triggered, the application stops running, and the application object is eliminated.
when a single user uses a web application, a session is started. Similar to an application, a session creates a user-specific session object and triggers the session_start event. In a session, each request triggers the application_beginrequest and application_endrequest events. In a session, the two events can be triggered multiple times to access different resources of the application. The session can be manually terminated or terminated due to no subsequent requests. Session seed triggers the session_end event to eliminate the session object.