我可以在ITicketStore
中使用MemoryCache
来存储AuthenticationTicket
吗?
背景:我的Web应用程序正在使用Cookie身份验证:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
LoginPath = new PathString("/Authentication/SignIn"),
LogoutPath = new PathString("/Authentication/SignOut"),
ReturnUrlParameter = "/Authentication/SignIn"
});
我的 Web API 使用访问令牌(OAuth2)来处理授权过程。
有时候(在某些浏览器上),会抛出以下异常:
未经处理的异常:分块 cookie 不完整。只找到了预期的 2 个块中的 1 个,总共 4021 个字符。可能已经超过了客户端大小限制。
显然,cookie 太大了。这很奇怪,因为我没有使用很多声明。它们都是默认声明(nameidentifier、nonce、exp 等)。现在,我正在尝试将自己的 ITicketStore 实现为 CookieAuthenticationOptions 上的 SessionStore。AuthenticationTicket 将存储在 MemoryCache 中(就像在这个 示例 中一样)。我对这整个主题非常陌生,不确定这是否是一个好方法,以及 MemoryCache 是否是一个有效的解决方案。