asp.net 实现一级域名与二级域名共享COOKIE
COOKIE可以自动由子级域名分享,无须做什么特别设置。对网站www.abc.com,check.abc.com来说,它们都是二级域名,一级域名是abc.com。所以,保存COOKIE的时候,将Cookie的Domain设置成“.abc.com”,无论www.abc.com还是check.abc.com,都可以顺利读取
public void WriteToCookie(int userId)
{
HttpCookie cookie = new HttpCookie(“UserInfo”);
cookie.Values.Add(“UserId”, userId.ToString());
cookie.Expires = DateTime.Now.AddHours(1);
cookie.Secure = false;
cookie.Domain = ".abc.com";
HttpContext.Current.Response.Cookies.Add(cookie);
}