During web development, page-to-page Jump is often involved. Page-to-page jump involves parameter transfer between pages. Passing parameters through URLs is one of the common methods, but Microsoft said: "Maximum URL length is 2,083 characters in Internet Explorer", that is, the URL has a length limit.
ASP. NET application front-end and back-end data exchange is completed through Form, form provides two data transmission methods: Get and post, the two data transmission methods vary greatly in actual transmission, but ASP.. NET Framework has shielded some differences between the two. Get is used to obtain data from the server, while post is used to submit data to the server. The two methods correspond to the get and post methods in the HTTP protocol during data transmission.
The get method adds the parameter data queue to the URL indicated by the Action attribute of the submission form, and uses "? "Separated, the values correspond to each field in the form one by one. It can be seen in the URL that it is the default from submission method. Due to the URL length limit, it can transmit a small amount of data.
The post mode places the data in the form carrier, and transmits the data to the URL pointed to by the action according to the corresponding variables and values. The post mode can transmit the information of a large amount of data to the server, generally, File Upload uses the POST method.
To solve the problem of passing parameters of large data volumes in get mode, use Post mode for data submission. The following is a method used to replace window. Open.
1. Javascript
/*
* Postnewwin
* Author: ppchen
*/
VaR postnewwin = function (URL ){
VaR urlarr = URL. Split ("? ");
VaR posturl = urlarr [0];
VaR postdata = urlarr [1];
VaR IFRAME = Document. getelementbyid ("postdata_iframe ");
If (! IFRAME ){
IFRAME = Document. createelement ("iframe ");
IFRAME. ID = "postdata_iframe ";
IFRAME. scr = "about: blank ";
IFRAME. frameborder = "0 ";
IFRAME. style. width = "0px ";
IFRAME. style. Height = "0px ";
VaR form = Document. createelement ("form ");
Form. ID = "postdata_form ";
Form. method = "Post ";
Form.tar get = "_ blank ";
Document. Body. appendchild (IFRAME );
Iframe.contentdomaindoc ument. Write ("<body>" + form. outerhtml + "</body> ");
}
Iframe.content+doc ument. getelementbyid ("postdata_form "). innerhtml = "<input name = 'postdata' id = 'postdata' type = 'text' value = '" + postdata + "'/> ";
Iframe.content1_doc ument. getelementbyid ("postdata_form"). Action = posturl;
Iframe.content1_doc ument. getelementbyid ("postdata_form"). Submit ();
};
2. CSHARP
/// <Summary>
/// Obtain parameters from Form
/// Author: ppchen
/// </Summary>
/// <Returns> parameter set </returns>
Private namevaluecollection parseformdata ()
{
Namevaluecollection squerystring = new namevaluecollection ();
If (this. Request. Form. Count> 0 & this. Request. Form ["postdata"]! = NULL)
{
String spostdata = This. Request. Form ["postdata"]. tostring ();
Spostdata = spostdata. Trim (New char [] {'&', ''});
If (! String. isnullorempty (spostdata ))
{
String [] sparameterlist = spostdata. Split ('&');
For (INT I = 0; I <sparameterlist. length; I ++)
{
String [] sparameter = sparameterlist [I]. Split ('= ');
For (Int J = 0; j <sparameter. length; j = J + 2)
{
Squerystring. Add (sparameter [J], httputility. urldecode (sparameter [J + 1]);
}
}
}
}
Return squerystring;
}
Open the page through the above JS Code on the client and obtain parameters on the server through the above CS code. In this way, the POST method is used to solve the URL length limit in the get method, you can pass parameters of large data volumes :)
The parameter is truncated because the URL is too long.