Solution for sharing sessions between multiple sites (sub-domains of a single domain)

Source: Internet
Author: User

 

//******
// Determine whether the cookie exists
If (Request. Cookies ["remrember"]! = Null & Request. Cookies ["remrember"] ["userName"]! = Null)
{

}
//******

//******
// Solution for sharing sessions with multiple sites
Response. Cookies ["remrember"] ["userName"] = Session ["UserId"]. ToString ();
Response. Cookies ["remrember"]. Domain = "8bao.com"; // key
Response. Cookies ["remrember"]. Expires = DateTime. Now. AddDays (1); // do not ignore
//******

Generated cookie (IE => Tools => internet Options => General => Settings => View files ):
Cookie name: Cookie: administrator@8bao.com/
Cookie content: remrember userName = xiaodi 8bao.com/1536 1765652096 29704949 1759498592 29704748 *

//******
// Delete the cookie of the shared Session
HttpCookie cookie = Request. Cookies ["remrember"];
Cookie. Expires = DateTime. Today. AddDays (-10 );
Cookie. Domain = "8bao.com"; // key
Response. Cookies. Add (cookie );
//******

 

Cookie deletion supplement:
Delete a Cookie (that is, the Cookie is physically deleted from the user's hard disk ). You cannot delete a Cookie because it is on your computer. However, you can have the browser Delete the Cookie for you. Set its validity period to a previous date. When the browser checks the Cookie validity period, the expired Cookie is deleted.

References:
Http://www.15seconds.com/issue/971108.htm

 

 

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.