ASP. NET --- get request, POST request, request, response and send-back Learning

Source: Internet
Author: User

Over the past few days, we began to learn ASP. NET technology. It can be said that most of the previous knowledge is based on ASP. NET technology. As long as the previous study is solid, this is quite understandable.

ASP. NET is an Active Server Page Technology Based on the. NET platform. You must know asp! = ASP. NET. ASP. NET:

1. Code-behind technology: Records of code and page separation;

2. object-oriented technology: provides a large number of controls and components;

3. In traditional Script Development, ASP. NET is a dynamic server page technology, which requires compiling on the server side and then sending the compiled results to the client.

  • Script technology:

Format: <% code segment %> A page can contain N code segments. In addition, the position of the code segment can be arbitrary. No matter how many code segments a page has, it is still a code segment. Methods cannot be defined in a code block. The code segment also follows the principle that variables are first defined and then used.

  • Output

Format: <% response. Write (object); %> or <% = Object %>

  • GET requests such as a page: http://www.baidu.gom/login.php? Name = ssss & Pwd = yyyy: the requested page is the login. PHP page, and two parameters name = ssss and Pwd = yyyy are passed to the login. PHP page.

It is worth noting that the links in the hyperlinks and the address bar are usually get requests and cannot be accessed directly on the receiving page. a null pointer exception may occur. Generally, hyperlinks are GET requests. However, GET requests have their own restrictions:

1. It is transmitted in plain text.

2. The parameter length is limited. The maximum length cannot exceed 255

  • POST request

Generally, the POST request is used for form submission:

1. It is transmitted in the form of a dark text.

2. The parameter length is unlimited.

  • Request: request. querystring [Key] is required for receiving GET requests.

The following lists several common ASP. NET objects:

1, response = httpresponse is used to output content to the client browser.

Common Methods: Write (string): to output content to the browser (text, HTML, CSS, JavaScript)

End (): end the current output stream.

2. Request = httprequest is used to get content from the client browser.

Common attribute: querystring: Get the parameter value in the GET request

--- Namevaluecollection item [Index]: obtains the value item [Key] based on the index: obtains the value based on the key.

Form: Get parameters in the post request

--- Namevaluecollection item [Index]: obtains the value item [Key] based on the index: obtains the value based on the key.

3. Server = httpserverutility: the object represents the server and some information about the server can be obtained.

Common method: urldecode (string): used for decoding. This method can only be used to interpret unicode encoding (% 20, etc)

Sending back is a very important technology. We will often encounter this technology in future studies. Sending a message back is to send the data to you and then process the data. Therefore, the following two conditions are met:

1. The request type must be post.

2. When posting data, the action points to the page itself.

The following is a simple POST request login code segment that uses ASP. NET technology to connect to the database. The first of the two aspx pages is the logon homepage, and the second is the two database pages:

 

<% @ Page Language = "C #" contenttype = "text/html" responseencoding = "UTF-8" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml"> 

 

<% @ Page Language = "C #" contenttype = "text/html" responseencoding = "UTF-8" %> <% @ import namespace = "system. data "%> <% @ import namespace =" system. data. sqlclient "%> <% string name = request. form ["name"]; string pwd1 = request. form ["pwd1"]; string pwd2 = request. form ["pwd2"]; If (pwd1! = Pwd2) {response. write ("two different passwords, please register again"); %> <a href = "01. aspx "> return </a> and enter registration again! <% Return;} string strcon = "Server = .; database = My; uid = sa; Pwd = 1 "; sqlconnection con = new sqlconnection (strcon); sqlcommand cmd = new sqlcommand (); Using (CON) {con. open (); Using (CMD) {cmd. connection = con; cmd. commandtext = "insert into Register values (@ name, @ PWD)"; cmd. parameters. add ("@ name", sqldbtype. varchar, 10); cmd. parameters ["@ name"]. value = Name; cmd. parameters. add ("@ PWD", sqldbtype. varchar, 20); cmd. parameters ["@ PWD"]. value = pwd1; cmd. executenonquery () ;}%>
<% @ Page Language = "C #" contenttype = "text/html" responseencoding = "UTF-8" %> <% @ import namespace = "system. data "%> <% @ import namespace =" system. data. sqlclient "%> <% string name = request. form ["name"]; string pwd1 = request. form ["pwd1"]; string pwd2 = request. form ["pwd2"]; If (pwd1! = Pwd2) {response. write ("two different passwords, please register again"); %> <a href = "01. aspx "> return </a> and enter registration again! <% Return;} string strcon = "Server = .; database = My; uid = sa; Pwd = 1 "; sqlconnection con = new sqlconnection (strcon); sqlcommand cmd = new sqlcommand (); Using (CON) {con. open (); Using (CMD) {cmd. connection = con; cmd. commandtext = "insert into Register values (@ name, @ PWD)"; cmd. parameters. add ("@ name", sqldbtype. varchar, 10); cmd. parameters ["@ name"]. value = Name; cmd. parameters. add ("@ PWD", sqldbtype. varchar, 20); cmd. parameters ["@ PWD"]. value = pwd1; cmd. executenonquery () ;}%>

 

 

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.