Difference between ASP. NET get and post

Source: Internet
Author: User
Tags html header id3
Form submission can be either a get method or a POST method. Check the following code to understand the differences between ASP. NET get and post:

<Form ID = "form1" method = "get" runat = "server">

<Div> name <asp: textbox id = "name" runat = "server"> </ASP: textbox> <br/>

Your website <asp: textbox id = "website" runat = "server"> </ASP: textbox> <br/>

<Asp: button id = "button1" runat = "server" text = "send"/> <br/>

Learn request and response usage <br/>

</Div>

</Form>

<Form ID = "form2" method = "Post" runat = "server">

<Div> name <asp: textbox id = "name2" runat = "server"> </ASP: textbox> <br/>

Your website <asp: textbox id = "website2" runat = "server"> </ASP: textbox> <br/>

<Asp: button id = "button2" runat = "server" text = "send"/> <br/>

Learn request and response usage <br/>

<Br/>

</Form>

From the URL, we can see the difference between ASP. NET get and post. So how can we program the data reception?

 

There are 1st types of data to be transmitted using the get method:
  1. Protected void page_load (Object sender, eventargs E)
  2. {
  3. String id = request. querystring ["name"];
  4. String website = request. querystring ["website"];
  5. Response. Write (ID + "<br>" + website );
  6. Response. Write ("you are using" + request. requesttype + "Data Transmission ");
  7. }

  

2nd. Write Method for receiving data transmitted using the POST method:
  1. Protected void page_load (Object sender, eventargs E)
  2. {
  3. String Id2 = request. Form ["name2"];
  4. String website2 = request. Form ["website2"];
  5. Response. Write (Id2 + "<br>" + website2 );
  6. Response. Write ("you are using" + request. requesttype + "Data Transmission ");
  7. }
3rd types of code that accepts both the get and post methods to send data: Write

1. String ID3 = request. Params ["name3"];

2. String website3 = request. Params ["website3"];

3. response. Write (ID3 + "<br>" + website3 );

B Writing Method

1. String ID4 = request ["name4"];

2. String website4 = request ["website4"];

3. response. Write (ID4 + "<br>" + website4 );

 

In form submission, the difference between ASP. NET get and post methods is summarized as follows:
      • Get gets data from the server, and post transfers data to the server.
      • Get adds the parameter data queue to the URL referred to by the Action attribute of the submission form. The values correspond to each field in the form one by one and can be seen in the URL. Post uses the http post mechanism to place fields in the form and their content in the HTML header and send them to the URL address referred to by the Action attribute. You cannot see this process.
      • For the get method, the server uses request. querystring to obtain the value of the variable. For the POST method, the server uses request. Form to obtain the submitted data.
      • The data size transmitted by get is small and cannot exceed 2 kb. The amount of data transmitted by post is large, which is generally not restricted by default.
      • Get has low security and high post security. However, the execution efficiency is better than the POST method.
    • Suggestion:
      • The get method is more secure than the POST method. If it contains confidential information, we recommend that you use the post data submission method;
      • We recommend that you use the get Method for Data Query. When adding, modifying, or deleting data, we recommend that you use the POST method.

 

 

 

 

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.