与えられた:
Domain 1: subdomain1.mydomain.com
Domain 2: subdomain2.mydomain.com
以下のコードを使用して「ドメイン 1」に Cookie を作成し、「ドメイン 2」の Cookie にアクセスしようとしています。
私の問題は、「ドメイン 2」が Cookie を認識したくないということです。何を与える?問題は .Domain プロパティにあると思いますが、ピリオドを前に置いたので、何が欠けていますか?
public void CreateCookie()
{
Boolean bNew = false;
HttpCookie oCookie = HttpContext.Current.Request.Cookies.Get("myData");
if (null == oCookie)
{
oCookie = new HttpCookie("myData");
bNew = true;
}
// Set the cookie value.
oCookie.Domain = ".mydomain.com";
oCookie.Secure = false;
oCookie["myid"] = "myid@whatever";
oCookie.Expires = DateTime.Now.AddDays(7);
if (true == bNew)
HttpContext.Current.Response.Cookies.Add(oCookie);
else
HttpContext.Current.Response.Cookies.Set(oCookie);
}
public String GetCookie()
{
String myid = null;
HttpCookie oCookie = HttpContext.Current.Request.Cookies.Get("myData");
if (null != oCookie)
myid = HttpContext.Current.Server.HtmlEncode(oCookie["myid"]);
return myid;
}
考え?