"2017-05-21" WebForm built-in objects: Session, Cookie, login and status hold

Source: Internet
Author: User
Tags server memory

1. Request-Gets the requested object

string s =request["key"];

2. Response-Response Request Object

Response.Redirect ("url"); Service End multiplicity orientation, jump on the current page.

Response.Write ("string"); Output this string to the top of the page, where you can put JS.

3. Session
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 connection to this session will be disconnected

Object type can be stored in session

(1), transfer value:

String S=textbox1.text;

session["AAA"]=S;

Response.Redirect ("url");

(2), Value:

label1.text= session["AAA"]. Tostring ();

(3), if error: Object reference is not set to an instance of an object.

Storage on the server side, occupying the memory of the servers. Once the browser is closed, the connection to this session will be disconnected

Handling: Judging when the value is taken

if (session["AAA"]!=null)

{

label1.text= session["AAA"]. Tostring ();

}

(4), if an object is passed:

Assignment: Users u= new users ();

U.username= "Lisi";

U.password= "123";

session["User"]=u;

Response.Redirect ("url");

Value: Users uu=session["user"] as Users;

Label1.text= UU. Username+uu. PassWord;

(5), the session after the end of the value can be directly released.

session["AAA"]=NULL;


4, the value of the Cookie can only wear string type.

Transmit value: string s =textbox1.text;

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

response.cookies["AA"].         Expires=datetime.now.adddays (3); Set Cookies3 days to expire.

Response.Redirect ("url");

Value:string ss=request.cookies["AA"]. Value;

Label1.text=ss;

If an error occurs: The object reference is not set to an instance of the object.

To judge when a value is taken

if (request.cookies["AA"]!=null)

{

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

Label1.text=ss;

}

Cookies are basically consistent with the session,
Not the same:cookies are stored on the client and can only be passed in string type.

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

Assignment value:
response.cookies["AA"]. Value = s;

Value:
string ss = request.cookies["AA"]. Value;

5, Login and status hold.

In the Click event of the Login screen login button:

To take a value in the main interface:

Exit Login button for the main interface:

"2017-05-21" WebForm built-in objects: Session, Cookie, login and status hold

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.