溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

ASP.NET中怎么實(shí)現(xiàn)Get和Post提交

發(fā)布時(shí)間:2021-07-16 11:55:46 來(lái)源:億速云 閱讀:122 作者:Leah 欄目:開(kāi)發(fā)技術(shù)

本篇文章為大家展示了ASP.NET中怎么實(shí)現(xiàn)Get和Post提交,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。

代碼如下:

< form id="form1" method="get" runat="server">
       < div>  姓名字< asp:TextBox ID="name" runat="server">< /asp:TextBox>< br />  
                  你的網(wǎng)站< asp:TextBox ID="website" runat="server">< /asp:TextBox>< br />
                   < asp:Button ID="Button1" runat="server" Text="send" />< br />
                  學(xué)習(xí)request 和 response的用法< br />
   < /div>
 </form>
 < form id="form2" method="post" runat="server">
       < div>  姓名字< asp:TextBox ID="name2" runat="server">< /asp:TextBox>< br />  
                  你的網(wǎng)站< asp:TextBox ID="website2" runat="server">< /asp:TextBox>< br />
                   < asp:Button ID="Button2" runat="server" Text="send" />< br />
                  學(xué)習(xí)request 和 response的用法< br />
     < br />
 </form>

從URL中可看出ASP.NET Get和Post的區(qū)別.那么那如何編程實(shí)現(xiàn)數(shù)據(jù)的接收呢?

  第1種,接收用get 方法傳輸?shù)臄?shù)據(jù)的寫(xiě)法:

 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("你使用的是" + Request.RequestType + "方式傳送數(shù)據(jù)");
       }

第2種,接收用post 方法傳輸?shù)臄?shù)據(jù)的寫(xiě)法:

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("你使用的是" + Request.RequestType + "方式傳送數(shù)據(jù)");
     }

第3種,同時(shí)接受get和post 方法傳送數(shù)據(jù)的代碼寫(xiě)法:  A 寫(xiě)法

  string id3 = Request.Params["name3"];
  string website3 = Request.Params["website3"];
  Response.Write(id3 + "< br>" + website3);

B 寫(xiě)法

   string id3 = Request.Params["name3"];
   string website3 = Request.Params["website3"];
   Response.Write(id3 + "< br>" + website3);

B 寫(xiě)法

   string id4 = Request["name4"];
   string website4 = Request["website4"];
   Response.Write(id4 + "< br>" + website4);

表單提交中,ASP.NET的Get和Post方式的區(qū)別歸納如下幾點(diǎn):

? get是從服務(wù)器上獲取數(shù)據(jù),post是向服務(wù)器傳送數(shù)據(jù)。

 get是把參數(shù)數(shù)據(jù)隊(duì)列加到提交表單的ACTION屬性所指的URL中,值和表單內(nèi)各個(gè)字段一一對(duì)應(yīng),在URL中可以看到。post是通過(guò)HTTP post機(jī)制,將表單內(nèi)各個(gè)字段與其內(nèi)容放置在HTML HEADER內(nèi)一起傳送到ACTION屬性所指的URL地址。用戶看不到這個(gè)過(guò)程。

 對(duì)于get方式,服務(wù)器端用Request.QueryString獲取變量的值,對(duì)于post方式,服務(wù)器端用Request.Form獲取提交的數(shù)據(jù)。

 get傳送的數(shù)據(jù)量較小,不能大于2KB。post傳送的數(shù)據(jù)量較大,一般被默認(rèn)為不受限制。

 get安全性非常低,post安全性較高。但是執(zhí)行效率卻比Post方法好

               建議:

 get方式的安全性較Post方式要差些,包含機(jī)密信息的話,建議用Post數(shù)據(jù)提交方式;

  在做數(shù)據(jù)查詢時(shí),建議用Get方式;而在做數(shù)據(jù)添加、修改或刪除時(shí),建議用Post方式

上述內(nèi)容就是ASP.NET中怎么實(shí)現(xiàn)Get和Post提交,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI