在将ASPNetCore 1.1项目迁移到ASPNetCore 2.0期间,我们偶然发现了Cookie-AuthN及其SessionStore
的问题。注入SessionStore的AspNet核心CookieAuthentication
ASP.NET核心1让我们做这样的事情:
public void ConfigureServices(...) {
Services.AddDistributedSqlServerCache(...);
Services.AddSingleton<DistributedCookieSessionStore>(); /// SQL based store
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory) {
var cookieOptions = app.ApplicationServices.GetRequiredService<IOptions<CookieAuthenticationOptions>>().Value;
cookieOptions.SessionStore = app.ApplicationServices.GetRequiredService<DistributedCookieSessionStore>();
app.UseCookieAuthentication(cookieOptions);
}
凌乱,但做的工作。
现在用ASP.NET睿2app.UseAuthentication()
没有签名允许修改的选项,我无法使用DI,获得会话存储的保持。