MVC 5의 ASP.NET ID와 함께 작동하도록 AutoFac을 설정했습니다. 모든 것이 표면에서 정상적으로 작동하는 것처럼 보였습니다. 즉, 사용자가 계정을 만들고 로그 할 수있었습니다. 그런데 보안 스탬프가 변경되면 사용자가 로그 아웃하지 않는다는 것을 발견했습니다. AspNetUsers 테이블에서 무차별 적으로 또는 암호를 변경하고 다른 브라우저에서 로그 아웃 할 것으로 예상되는 사용자가.MVC 5의 ASP.NET ID가있는 Autofac은 OWIN 파이프 라인의 보안 스탬프를 확인하지 않습니다.
다음은 this unofficial article에 따라 자동 완성을 설정하는 방법입니다.
public void Configuration(IAppBuilder app)
{
var builder = new ContainerBuilder();
builder.RegisterType<ApplicationDbContext>().AsSelf().InstancePerRequest();
builder.RegisterType<ApplicationUserStore>().As<IUserStore<ApplicationUser>>().InstancePerRequest();
builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerRequest();
builder.RegisterType<ApplicationSignInManager>().AsSelf().InstancePerRequest();
builder.Register<IAuthenticationManager>(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
builder.Register<IDataProtectionProvider>(c => app.GetDataProtectionProvider()).InstancePerRequest();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
ConfigureAuth(app);
}
쿠키 인증 미들웨어를 설정하는 방법입니다. 유효 기간 간격 시간 간격이 더 짧은 것을 제외하면 기본값입니다.
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromSeconds(15),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
}
내가 GenerateUserIdentityAsync에 중단 점을 설정하면 다음이 호출되는 경우에만 처음에 사용자가 로그인.