asp.net中Cookie跨域问题

以下是创建一个跨域的Cookie,只能实现同一个根域下的Cookie

如:www.126.com,在这个根域下的所有二级域名可共享Cookie,{mail.126.com,photo.126.com}

public static bool CreateCookie(string strCookieName, string strCookieValue, string strDomain, bool blURLEncode)

{

if (blURLEncode)

{

strCookieValue = System.Web.HttpContext.Current.Server.UrlEncode(strCookieValue);

}

HttpCookie objCookie = new HttpCookie(strCookieName, strCookieValue);

objCookie.Domain = strDomain; //设置Cookie的域名

System.Web.HttpContext.Current.Response.Cookies.Add(objCookie);

return true;

}