Built-in objects (Session, application, ViewState)

Source: Internet
Author: User

Built-in objects: for cross-page values and state retention. →http of the non-state of the

"4,"Session:
Each computer accesses the server, it will be a separate set of Session,key values are the same, but the content is not the same

All of the above is the same as cookies.

Not the same:
1, the session save location is saved on the server
2, the session does not have a lasting, its preservation period is 20 minutes

Focus: Do not abuse the session, do not use, misuse may cause server content overflow, do not cause waste of resources, because in-memory data extraction and interaction is the fastest

Assignment: session["key"] = value;
Value: String a = session["key"];
Clear: session["key"]=null;

Denglu.aspx Interface:

 protected voidPage_Load (Objectsender, EventArgs e) {Button1.Click+=button1_click; }    voidButton1_Click (Objectsender, EventArgs e) {        stringUname =TextBox1.Text; session["User"] = Uname;//Assign Valuesession["Zhi1"] = TextBox3.Text;//send a value again .Response.Redirect ("xianshi.aspx"); }

Xianshi.aspx Interface:

 protected voidPage_Load (Objectsender, EventArgs e) {        if(session["User"] ==NULL)//Take value{Response.Redirect ("denglu.aspx"); }        Else{Label1.Text="Hello,"+session["User"]; //When you pass the second value, the display is finished. Closelabel1.text+=session["Zhi1"]; session["Zhi1"]=NULL;//do not need to hold when        }    }

"5,"Application:

Global objects
application["Key"] is all the user gets the value of this key is the same
Without a save cycle, it will always be saved
Where it's usually used, the version number

Assignment value: application["key"]= value;
Value: Application.get ("key");

Denglu.aspx interface: application["Banben"] = "V1.3";

Xianshi.aspx Interface: Response.Write ("Current version number:" +application.get("Banben"));

"6,"ViewState:

Understand the case and record the content information of the previous page.

1) The session value is stored in the server memory, then, it is certain that a large number of use of the session will result in a heavier server burden. Instead of ViewState server resources by simply depositing data into a page-hidden control, we can save variables and objects that require the server to "remember" into viewstate. Sesson should only be applied to variables and object stores that require cross-pages and are related to each access user.

ViewState is not able to store all of the. NET type data, it only supports string, Integer, Boolean, Array, ArrayList, Hashtable, and some types of customizations.

Everything has two sides, using ViewState will increase the output of the page HTML, the use of more bandwidth, which we need to consider carefully. In addition, since all viewstate are stored in a hidden domain, the user can easily view the source code to see this base64 encoded value. Then you can get the object and variable values that you store in the conversion.

Built-in objects (Session, application, ViewState)

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.