二级域名如何写cookie
二级域名如何写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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步