Session and cookie operations

Source: Internet
Author: User

1. Add a value to the session:

Session. Add ("provider", Doker. Website. appcode. Global. currentuser. username );

Obtain the value of IF (session ["provider"]! in the session. = NULL)
{
String provider = session ["provider"]. tostring ();
}

Delete Sessionsession. Abandon ();
Session. Clear ();

In the web. <sessionstate mode = "inproc" stateconnectionstring = "TCPIP = 127.0.0.1: 42424" sqlconnectionstring = "Data Source = 127.0.0.1; trusted_connection = yes "cookieless =" false "timeout =" 50 "/>

I use session to save user permissions. My system is a large file to be uploaded, usually 50 MB. Why is the local test session not lost, but put it on the server, when users upload large files, the system can easily exit? Hope you can help me solve the problem. Thank you! So I decided to change the cookie to save the user's permission!
2. Assign httpcookie acookie = new httpcookie ("provider") to the cookie ");
Acookie. value = Doker. Website. appcode. Global. currentuser. Username;
Acookie. expires = datetime. Now. adddays (1 );
Response. Cookies. Add (acookie );

Obtain the cookie value if (request. Cookies ["provider"]! = NULL)
{
String provider = server. htmlencode (request. Cookies ["provider"]. value );
}

Delete the cookie value httpcookie acookie;
String cookiename;
Int Limit = request. Cookies. count;
For (INT I = 0; I <limit; I ++)
{
Cookiename = request. Cookies [I]. Name;
Acookie = new httpcookie (cookiename );
Acookie. expires = datetime. Now. adddays (-1 );
Response. Cookies. Add (acookie );
}

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.