それはおそらく問題だあなたが経験したCookieドメインに関してでした。クッキーは"." + FormsAuthentication.CookieDomain
に書き込まれる可能性があります。前に "admin.example.com"ドメインにクッキーを設定していて、クッキーの先頭に.
が付いています。開発環境では、localhost
に書き込まれます。私が使用する解決策は、認証CookieとセッションCookieごとに2つのCookieを追加することです。
続くように私が使用しているソリューションです:
protected void SignOut(HttpContext Context)
{
FormsAuthentication.SignOut();
Context.Session.Abandon();
// clear authentication cookie
Context.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName)
{
Path = FormsAuthentication.FormsCookiePath,
Value = "",
Domain = (Convert.ToString(FormsAuthentication.CookieDomain).Length > 0) ? Convert.ToString(FormsAuthentication.CookieDomain) : Context.Request.Url.Host,
HttpOnly = true,
Expires = DateTime.Now.AddYears(-1)
});
Context.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName)
{
Path = FormsAuthentication.FormsCookiePath,
Value = "",
Domain = (Convert.ToString(FormsAuthentication.CookieDomain).Length > 0) ? "." + Convert.ToString(FormsAuthentication.CookieDomain) : "." + Context.Request.Url.Host,
HttpOnly = true,
Expires = DateTime.Now.AddYears(-1)
});
// clear session cookie (not necessary for the current problem but recommended anyway)
Context.Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId")
{
Path = FormsAuthentication.FormsCookiePath,
Value = "",
Domain = (Convert.ToString(FormsAuthentication.CookieDomain).Length > 0) ? Convert.ToString(FormsAuthentication.CookieDomain) : Context.Request.Url.Host,
HttpOnly = true,
Expires = DateTime.Now.AddYears(-1)
});
Context.Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId")
{
Path = FormsAuthentication.FormsCookiePath,
Value = "",
Domain = (Convert.ToString(FormsAuthentication.CookieDomain).Length > 0) ? "." + Convert.ToString(FormsAuthentication.CookieDomain) : "." + Context.Request.Url.Host,
HttpOnly = true,
Expires = DateTime.Now.AddYears(-1)
});
FormsAuthentication.RedirectToLoginPage();
}
この呼び出しの結果は応答
場所に次のヘッダーを追加します。/Login.aspx? ReturnUrl =デフォルト。aspx
Set-Cookie:**** =; expires = Tue、1999年10月12日05:00:00 GMT;パス= /; HttpOnly
セットクッキー:**** =; domain = admin.example.com;有効期限=水曜日、2014年4月23日18:04:58 GMT;パス= /; HttpOnly
セットクッキー:**** =; domain = .admin.example.com;有効期限=水曜日、2014年4月23日18:04:58 GMT;パス= /; HttpOnly
Set-Cookie:ASP.NET_SessionId =; domain = admin.example.com expires =水曜日、2014年4月23日18:04:58 GMT;パス= /; HttpOnly
Set-Cookie:ASP.NET_SessionId =; domain = .admin.example.com expires = Wed、23-Apr-2014 18:04:58 GMT;パス= /; ***
は私の暗号化された認証チケット値を含む私のクッキーの名前ですHttpOnlyの
。最初Set-Cookie
はおそらくFormsAuthentication.SignOut()
メソッド呼び出しから生成されること
注意。
一般的な問題の1つは、クッキーがあるコンテキストで設定され、別のコンテキストから削除しようとすることです。例えば。削除Set-Cookieヘッダーのパス属性とドメイン属性が元のSet-Cookie呼び出しの属性と正確に一致することを確認してください。 – EricLaw
残念ながら、私が言ったように、私はそれを支配していません。 FormsAuthentication.RedirectFromLoginを呼び出してCookieを設定し、WebサービスのLogOutメソッドを呼び出します。 – R4cOON