ASP.net learning summary, asp.net Summary

Source: Internet
Author: User

ASP.net learning summary, asp.net Summary

I learned that ASP.net once again came into contact with B/S development. The following figure summarizes the macro structure of ASP.net. Next, we will introduce the six objects in ASP.net in detail.

1. The Request obtains data from the client, including form-based data and parameter list information sent through the URL. It can also receive Cookie information from the user.

A Request is a specific object in the HttpRequest class. Main attributes include:

The Request. Form attribute is used to obtain data.

Between form data: note that the submission method should be set to "Post ".

 

Request. QueryString attribute to obtain data. You can obtain a set of HTTP query string variables. You can read the address information. Note that the submission method is set to "Get ".

 

Difference between Post and Get

In ASP.net, data is sent to the server through a form. There are two data transmission methods (HTML): Post and Get. Get attaches the transmitted data to the end of the URL. The Post method encapsulates the transmitted data as a dataset for transmission.

Reading information during Post

String strUserName = Request. Form. Get ("txtUserName"). ToString (); note that form is equivalent to a set. Therefore, there are multiple methods to obtain the corresponding data. String strUserName = Request. Form ["txtUserName"]. ToString ();

Get method information reading

String strUserName = Request. QueryString ["txtUserName"]. ToString ();

String strUserName = Request. QueryString. Get ("txtUserName"). ToString ();

Summary

Either way, you can use this method: Request ["txtUserName"]. ToString (); to obtain data.

2. Response is used to output data to the client, including outputting data to the browser, redirecting the browser to another url, or outputting data to the browser

Response is an object of the HttpResponse class. Attributes and methods:

Response. Write () sends string information to the client.

Response. Buffer is used to control whether the Response cache is used. The default value is true.

Response. Clear () clears the data in the cache, so that the data in the cache area that is not sent to the browser is cleared.

3. The Server provides access to properties and methods on the Server.

The class name is HttpServerUtility. The main attributes and methods are as follows:

MachineName: obtains the name of the server computer.

ScrptTimeout: used to specify the time period for the script to run on the server before termination.

Method description:

CreateObject creates a server instance of the COM object.

Execute to Execute another aspx page on the current server. After executing this page, return to this page to continue execution.
HtmlEncode encodes the string to be displayed in the browser and returns the encoded string.
HtmlDecode decodes HTML encoded strings and returns decoded strings.
MapPath returns the physical file path corresponding to the specified virtual path on the Web server.
Transfer terminates the execution of the current page and starts executing a new page for the current request.

UrlEncode encodes the string representing the URL for reliable HTTP transmission from the Web server to the client through the URL.
UrlDecode decodes the encoded URL string and returns the decoded string.
UrlPathEncode encodes the URL part of the URL string and returns the encoded string.

4. The Application acts on the State object of the entire Application.

 

Method:

Add or create an object

Application. Add ("key", value); or Application ("key") = value;

Obtains the value of an object in the Application set.

Int I = (int) Application ("key"); or int I = Application. Contents ["key"]; or int I = Application. Get ("key ")

Update object values in a set

Application. set ("key", value); or Application ["key"] = (int) Application ["key"] + 1; it is best to add the lock mechanism when updating: application. lock () and Application. unLock ().

Remove objects

Application. Remove ("key"); Remove the specified object. Application. RemoveAll (); or Application. Clear () removes all objects.

Basic events

Application_Start, Application_End, and Application_Error. These events are in the Global. asax file. Global. an optional asax file (either available or only available, this file contains the application-level and session code (events) returned to the ASP.net application or HTTP module ).

5. Session-level objects. Users track sessions of a single user. For example, the implementation of Website access traffic. Methods and attributes are similar to Application.

6. Cookie: stores data information in the same way as Application and Session. Is a piece of text that the Web server saves on the user's hard disk. Cookie allows a Web site to save information on a user's computer and then retrieve it. Information fragments are stored as 'key/value' pairs.
Cookie is a text file stored on the client's hard disk. It can store information about a specific client, session, or application. It corresponds to the HttpCookie class in. NET.
There are two types of cookies: Session Cookie and persistent Cookie. The former is temporary. Once the session state ends, it will no longer exist. The latter has a fixed expiration date, and the Cookie will be stored on the user's computer as a text file before it expires.
You can use the Response object to create a Cookie on the server and output it to the client.

Learning Experience: The above is an introductory summary of the objects in ASP.net. the most useful thing in ASP.net videos is the use of controls. In addition to the two types that make me feel interesting, there are two types of verification controls, including mandatory fields, comparison controls, range comparison, regular expressions, custom verification, and verification summary. Through these verifications, we can register information on the Internet. The other is the use of DataSet objects in ADO.net,. NET data providers, and control templates for displaying data. Some of the controls introduced in ASP.net have been used in niuyun. They have gained a deeper understanding through video explanations and implementation examples.

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.