我正在使用 cookie 進行表單身份驗證的 .net 網站上工作,我想添加另一個安全 cookie 來保存訪問和刷新令牌。正在將 cookie 添加到Response.Cookies并且一切似乎都很好。我使用 fiddler 檢查響應標頭以確保Set-Cookie設置了標頭。HTTP/1.1 302 FoundCache-Control: no-cache, no-storePragma: no-cacheContent-Type: text/html; charset=utf-8Expires: -1Location: /Set-Cookie: TestTokenCookie=(truncated for brevity); domain=local.foobar.com; expires=Sun, 18-Nov-2018 14:42:56 GMT; path=/X-Frame-Options: SAMEORIGINX-UA-Compatible: IE=Edge,chrome=1Date: Mon, 20 Aug 2018 13:42:59 GMTContent-Length: 118響應看起來正確,但瀏覽器中沒有出現 cookie。我正在使用 Edit This Cookie chrome 擴展程序來查看已設置的 cookie。這是我使用的設置 cookie 的代碼。public void CreateTokenCookie(TokenCookieData tokenCookieData, HttpContextBase currentContext, bool createPersistentTicket = true){ var ticket = new FormsAuthenticationTicket(1, tokenCookieData.Username, DateTime.Now, DateTime.Now.AddDays(90), createPersistentTicket, tokenCookieData.ToString()); CreateCookieFromTicket(ticket, TOKEN_COOKIE_NAME, true, currentContext);}private void CreateCookieFromTicket(FormsAuthenticationTicket ticket, string cookieName, bool httpOnly, HttpContextBase currentContext){ var encryptedTicket = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(cookieName, encryptedTicket) { HttpOnly = httpOnly, Secure = FormsAuthentication.RequireSSL, Path = FormsAuthentication.FormsCookiePath, Expires = ticket.Expiration }; var domain = GetCookieDomain(); if (domain != null) { cookie.Domain = domain; } if (currentContext.Response.Cookies[cookieName] != null) { currentContext.Response.Cookies.Remove(cookieName); } currentContext.Response.Cookies.Add(cookie);}任何想法為什么沒有在瀏覽器中設置 cookie?
2 回答

侃侃爾雅
TA貢獻1801條經驗 獲得超16個贊
我認為問題可能是您的域“domain=local.test.com;”
有關更多詳細信息,請參閱此https://stackoverflow.com/a/24071239/10241547
test.com 似乎是該限制列表的一部分
或者可能是 com
// com : https://en.wikipedia.org/wiki/.comcom
請參閱:https : //publicsuffix.org/list/public_suffix_list.dat
- 2 回答
- 0 關注
- 598 瀏覽
添加回答
舉報
0/150
提交
取消