【发布时间】:2017-03-30 12:57:27
【问题描述】:
我可以在ITicketStore 中使用MemoryCache 来存储AuthenticationTicket 吗?
背景:我的网络应用正在使用 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 等)。我现在正在尝试在CookieAuthenticationOptions 上实现我自己的ITicketStore 作为SessionStore。 AuthenticationTicket 将存储在 MemoryCache 中(就像在这个 sample 中一样)。我对整个主题很陌生,不确定这是否是一种好方法以及MemoryCache 是否是有效的解决方案。
【问题讨论】:
-
github.com/aspnet/Security/issues/830 这个 github issue 可能对你有帮助。
标签: c# authentication cookies asp.net-core asp.net-identity