2017-12-01 20 views
-1

Asp.Net MVC 프로젝트의 로그인 기능을 연구 중입니다. 나에게 거짓 기억한다면나를 기억하는 경우 Asp.Net MVC ID는 사용자를 로그 아웃하지 않습니까?

  1. 하고 나는 사용자가 로그 아웃해야 15 분을위한 상호 작용이 없다 :

    내 응용 프로그램에서 두 가지 시나리오가 있습니다.

  2. 나를 기억하는 경우 분이 지나면 로그 아웃하지 말고 5 시간 후에 쿠키를 지워야합니다.

나는 인터넷에서 많이 검색 한 나의 app.UseCookieAuthentication 수정 :

그것은 15 분 후에 세션을 만료 여부 나 사실인지 기억 하는가? 내가 도대체 ​​뭘 잘못하고있는 겁니까?

app.UseCookieAuthentication(new CookieAuthenticationOptions 
{ 
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
    LoginPath = new PathString("/Account/Login"), 
    Provider = new CookieAuthenticationProvider 
    { 
     // Enables the application to validate the security stamp when the user logs in. 
     // This is a security feature which is used when you change a password or add an external login to your account. 
     OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
     validateInterval: TimeSpan.FromMinutes(500), 
     regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager) 
    ) 
    }, 
    SlidingExpiration = true, 
    ExpireTimeSpan = TimeSpan.FromMinutes(15) 
}); 

답변

1

그것은이 라인에 기인한다 :

ExpireTimeSpan = TimeSpan.FromMinutes(15) 

이 쿠키는 항상 후 15 분 만료 의미합니다.

사용자가 Remember me?을 선택한 경우 ExpireTimeSpan을 5 시간으로 설정하고 15 분으로 설정하면 사용자가 로그인 양식을 제출하는 곳을 확인해야합니다.

업데이트

나는 당신의 로그인 코드가 어떻게 생겼는지 모르겠어요하지만 당신은 사용자가 당신이 비슷한해야합니다 Remember me? 선택하는 경우에 따라 다른 동작을 원하는 경우 :

await HttpContext.SignInAsync(
    CookieAuthenticationDefaults.AuthenticationScheme, 
    new ClaimsPrincipal(claimsIdentity), 
    new AuthenticationProperties 
    { 
     IsPersistent = true, 
     ExpiresUtc = DateTime.UtcNow.AddMinutes(20) 
    }); 

더 details and examples https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie?tabs=aspnetcore2x

+0

어떻게 Action에서'ConfigureAuth'로'ExpireTimeSpan'을 전달할 수 있습니까? –

+0

예를 추가했습니다. 추가 정보가 필요하면 로그인 방법을 포함시켜주십시오. – timothyclifford