Web-side session Cookies application ViewState

Source: Internet
Author: User
Tags server memory

URL pass-through value/querystring
1, do not occupy server memory
2, the confidentiality of poor, the length of the transfer value is limited

Because of the poor confidentiality of the previous article, the limited value of the length can only be passed a string type value

The knowledge of this article is

Session

Assign value

String S=textbox1.text;

session["AA"]=s; AA is a value-only name that can also be used to accept the name of the value you are passing.

Response.deriect ("default.aspx");

Take value

label1.text=session["AA"].tostring ();

Let's say there's a student class pass value

Student s=new Student ();

S.name= "Zhang San";

S.sex=true;

session["AA"]=s;

Response.dedirect ("default.aspx");

Accept

Student s=session["AA"] as Student;

Label1.text=s.name;

Storage in server memory
Very good, very fast
Do not abuse, easy overflow

Life cycle: 20 minutes, every new request will refresh this time

Once the browser is closed (the same browser is not a page), then the connection to this session will be disconnected

Cookies
Identical to the session
Not the same place: Cookies are stored on the client's

Pass Value

String S=textbox1.text;

response.cookies["AA"].value=s;

Take value

if (request.cookies["AA"]!=null) assumes that no accepted value is set to the object null

{

String ss=request.cookies["AA"].value;

Label1.text=ss;

}

Identical to the session
Not the same place: Cookies are stored on the client's

Session is safe, but consumes server memory
Cookies, which do not consume server memory, exist on the client, but may be accessed

Persistent cookies

Assuming a period of 3 days

request.cookies["AA"]. Expires=datetime.now.adddays (3);

Withdrawal period is not held for a negative period

request.cookies["AA"]. Expires=datetime.now.adddays (-10);

Application

The pass value is the same as the session

application["AA"]=TEXTBOX1.TEXT;

Response.dedirect ("Default.aapx");

Take value

String s=application["AA"].tostring ();

Label1.text=s;
Storage on the server side, consuming server memory (as long as the server does not shut down or restarts)
Life cycle: Permanent (can be used as temporary database)

This is the object that everyone accesses.

Web-side session cookies 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.