Web API Cookie 和会话存储

Web API Cookies and Session Storage

我们有一个由 OWIN Cookie 身份验证中间件发布的 cookie 保护的 Web API。

除了 Cookie Auth 中间件生成的通用身份验证字段外,cookie 还存储自定义字段,例如用户 ID、姓名、...

在负载均衡器后面部署了多个 Web API 实例的情况下,我们是否需要在 SQL/Redis/... 中保留会话?

谢谢。

所以听听 Cuong Le 所说的并查看 Microsoft.Owin.Security.Cookies 的 source code 可以看到默认情况下服务器端不需要存储。

仅当设置 属性 IAuthenticationSessionStore 时才需要存储。源代码注释如下:

    /// <summary>
    /// An optional container in which to store the identity across requests. When used, only a session identifier is sent
    /// to the client. This can be used to mitigate potential problems with very large identities.
    /// </summary>
    public IAuthenticationSessionStore SessionStore { get; set; }

希望对您有所帮助!