我正在使用 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 关注
- 544 浏览
添加回答
举报
0/150
提交
取消