二级域名如何写cookie
主站:www.zzm.com
子站:shop.zzm.com
<appSettings>
<add key="EJJJCookieDomainName" value="zzm.com"/>
</appSettings>
两个项目下的web.config都写入这个节点
写cookie的时候读取此节点的value,把cookie写在此域名下。二级域名也就写进cookie了。
#region 写登录Cookie
public static int WriteCookie(string UserID, string UserName,string UserType,bool remember)
{
HttpCookie userCookie = new HttpCookie("Deco");
userCookie.Domain = System.Configuration.ConfigurationManager.AppSettings["EJJJCookieDomainName"].ToString();
userCookie.HttpOnly = true;
if(remember)
{
userCookie.Expires = DateTime.Now.AddYears(1);
}
userCookie["DecoUName"] = HttpUtility.UrlEncode(UserName);
userCookie["DecoUID"] = UserID;
userCookie["DecoUType"] = UserType;
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
HttpContext.Current.Response.Cookies.Remove("Deco");
HttpContext.Current.Response.Cookies.Add(userCookie);
return 1;
}
#endregion