.NET page among several methods of traditional values

1. QueryString

  This is the simplest way of traditional values, but the drawback is the value of preaching and can not pass objects displayed in the address bar of your browser, applies only to deliver value simple and secure less demanding.

  传递:  location.href="WebForm2.aspx?name=" + yourName&&name2="+ yourName2;

  接收:  string name = Request.QueryString["name"];

 

2. Form

  Delivery: The name and the form controls the delivery value, such as:

       <form id="form1" method="post">

          <input type="text" name="name" value="xxx" />

       </form>

       Form to be submitted <input type = "submit" /> or document.getElementById ( "form1") submit ().;

  接收:  string name = Request.Form["name"];

 

3. Session

  Note that in Session variables to store too much data consumes more server resources, you should use some cleanup actions when using the session to remove some unwanted session.

  移除:  Session.Remove("name");

  传递:  Session["name"] = yourName;

  接收:  string name=Session["name"].ToString();

 

4. Cookie

  传递:  HttpCookie cookie_name = new HttpCookie("name");

       cookie_name.Value = yourName;

       Response.AppendCookie(cookie_name);

  接收:  Request.Cookies["name"].Value;

 

5. Application

  Scope is the entire global Application object, that is valid for all users. Lock with their usual methods and UnLock.

  Transfer: Application [ "name"] = name;

  Receiving: Application.Lock ();

      string name = Application["name"].ToString(); 

      Application.UnLock();

      // Lock purpose is to prevent multiple threads tampered with, to ensure that this time only change yourself

 

6. Server.Transfer

  transfer:

  WebForm1 written as attribute values ​​need to be transmitted:

  public string Name { get{ return txtName.Text; } }

  Execution Server.Transfer ( "WebForm2.aspx");

   

  receive:

  WebForm2 received parameters:

  WebForm1 wf1=(WebForm1)Context.Handler;

  Response.Write( wf1.Name );

Reproduced in: https: //www.cnblogs.com/-maomao/p/4125707.html

Guess you like

Origin blog.csdn.net/weixin_33860528/article/details/93760714