siteA.comはsitecookie.com/cookies.ashxを呼び出し、sitecookie.comドメインのCookie「cookiename」を設定します。同じブラウザ、同じウィンドウ、新しいタブ、siteB.comはsitecookie.com/cookies.ashxを呼び出し、同じcookie「cookiename」(これもsitecookie.comドメイン用)を取得しようとしますが、nullです。
Cookies.ashxは、IHttpHandler、IReadOnlySessionStateを実装し、conformsTo [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
だから問題は、なぜそれがnullであり、それを取得できるのかということです。
これは私がsiteAとsiteBからリクエストをする方法です:
WebClient fs = new WebClient();
var data = fs.DownloadData("http://sitecookie.com/cookies.ashx");
var tostring = System.Text.Encoding.ASCII.GetString(data);
return tostring;
これは私がcookies.ashxでcookieを読み取る方法です。戻り値は文字列です。
var cookie = context.Request.Cookies["cookiename"];
if (cookie != null) return cookie.Value;
return "false";
これは私がcookies.ashxにクッキーを書く方法です
HttpCookie cookie = new HttpCookie("sso");
cookie.Value = context.Request.QueryString["token"];
cookie.Expires = DateTime.Now.AddDays(1);
context.Response.AppendCookie(cookie);
return "true";