0

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";
4

2 に答える 2

1

http://sitecookie.com/cookies.ashxへのすべての呼び出しが新しい要求として扱われ、asp.netが新しいsessionIdを開始するため、これは不可能であることがわかりました。永続化する唯一の方法は、セッションIDを保存し、それを後続の各リクエストに渡すことです。多くのクライアントがサービスを呼び出しており、それらのクライアント間でセッションIDを渡すことができないため、このソリューションは機能しません。

于 2012-07-24T15:06:14.637 に答える
0

あなたの答えは正しいですが、その後の.ashx呼び出しの間にCookieを取得することは可能です。.ashxファイルコードの先頭で、ファイルまたはデータベースレコード(名前付きパイプを介してデータベースと通信します)からCookieを「取得」し、それらを「保存」するために、.ashxファイルが必要です。 .ashxファイルコードの最後にある同じファイルまたは同じデータベースレコード。

Don't forget to record these essential components of your cookie: Name, Value, Domain, HttpOnly, Secure and Path and regenerate the cookies with these components set correctly or else nothing will work! But - if you do it correctly you CAN 'fool' your remote server - which possibly creates the cookies in the first place - to see no difference in your .ashx file code invocations when you communicate with it (using Http?) and passing its own cookies back and forth in a cookie container. Good luck ..

于 2014-01-08T08:39:10.183 に答える