我已经使用 Redis 实现了 cookie 存储。我大部分时间都遵循这个代码示例......
我的 Startup.Auth 类没有什么特别之处:
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
IDataProtector dataProtector = app.CreateDataProtector(typeof(RedisAuthenticationTicket).FullName);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
LoginPath = new PathString("/Login.aspx"),
LogoutPath = new PathString("/Register.aspx"),
SessionStore = new RedisSessionStore(new TicketDataFormat(dataProtector)),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromSeconds(300),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
}
});
...
我的印象是,实现 SessionStore 意味着我在浏览器中看到的唯一会话 cookie 是 ASPNET_SessionId,但我的应用程序在登录后似乎仍然创建了一个 AspNetCookie ......这肯定来自 Owin 启动 - 我可以改变它的名字来自我的创业公司。
我的 AuthenticationSessionStore 类正在启动并从 Redis 获取身份验证 cookie。我只是不明白为什么这个 Cookie 仍然存在,如果它是设计的?
