Analysis of ASP. NET Get and Post submission methods

Source: Internet
Author: User

Copy codeThe Code is as follows: <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:

Copy codeThe Code is as follows: protected void Page_Load (object sender, EventArgs e)

{

String id = Request. QueryString ["name"];

String website = Request. QueryString ["website"];

Response. Write (id + "<br>" + website );

Response. Write ("you are using" + Request. RequestType + "Data Transmission ");

}

2nd. Write Method for receiving data transmitted using the post method:

Copy codeThe Code is as follows: protected void Page_Load (object sender, EventArgs e)

{

String id2 = Request. Form ["name2"];

String website2 = Request. Form ["website2"];

Response. Write (id2 + "<br>" + website2 );

Response. Write ("you are using" + Request. RequestType + "Data Transmission ");

}

3rd types of code that accepts both the get and post methods to send data: Write

Copy codeThe Code is as follows: string id3 = Request. Params ["name3"];

String website3 = Request. Params ["website3"];

Response. Write (id3 + "<br>" + website3 );

B Writing Method

Copy codeThe Code is as follows: string id3 = Request. Params ["name3"];

String website3 = Request. Params ["website3"];

Response. Write (id3 + "<br>" + website3 );

B Writing MethodCopy codeThe Code is as follows: string id4 = Request ["name4"];

String website4 = Request ["website4"];

Response. Write (id4 + "<br>" + website4 );

In form submission, the difference between ASP. NET Get and Post methods is summarized as follows:

• Get is to get data from the server, and post is to send 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.

It's not an alarm clock that wakes up every morning!

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.