2014-03-02 1 views
7

세션을 어떻게 무효화합니까?
생식 : 내 사이트 MVC5 ID로 세션을 어떻게 무효화합니까?

  • 과 관련된
  • 수출 쿠키를 일반 계정을 사용하여

    1. 로그인 로그 아웃 버튼을 I 사이트에서 로그 아웃하고있어
    2. 확인을 클릭하고 쿠키는
    3. 지워집니다
    4. 2 단계에서 복사 한 쿠키 가져 오기
    5. 로그인 프로세스를 거치지 않고 사이트에 다시 로그인했습니다.

    이전에 복사 한 쿠키를 무효로 만들 수 있습니까?

    표준 MVC5 로그 오프 기능을 사용하고 있습니다.

    public ActionResult LogOff() 
        { 
         AuthenticationManager.SignOut(); 
         return RedirectToAction("Index", "Home"); 
        } 
    
    
        private IAuthenticationManager AuthenticationManager 
        { 
         get 
         { 
          return HttpContext.GetOwinContext().Authentication; 
         } 
        } 
    

    쿠키 만 로그 아웃하려고 시도했습니다.

    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); 
    

    SecurityStamp를 변경하면 문제가 해결되지만 주장이 변경되지 않았으므로 스탬프도 마찬가지입니다.

    UserManager.UpdateSecurityStampAsync(user.UserName); 
    

    설명서에 세션을 무효화해야한다고 말하는이 기능을 사용해 보았습니다. http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.abandon(v=vs.110).aspx

    Session.Abandon(); 
    
  • +0

    의 중복 가능성 http://stackoverflow.com/questions/20681726 : 세션을 추적

    /asp-net-identity-logout) – davethecoder

    +1

    이것은 중복되지 않습니다. –

    +0

    동의합니다. 중복 질문이 아닙니다. –

    답변

    0

    나는 쿠키 자체를 "무효화"하는 방법을 몰라,하지만 당신이 필요로하는 것은 다시 사용하는 쿠키를 요청을 무효로하는 경우에, 당신은 세션의 상태를 추적 할 수 있으며, 요청 인증 후이 상태를 확인하십시오.

    public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) 
    { 
        ... 
        await SignInAsync(user, model.RememberMe); 
        Session["IsValid"] = true;   // Tells that the session is valid 
        ... 
    } 
    
    public ActionResult LogOff() 
    {   
        AuthenticationManager.SignOut(); 
        Session["IsValid"] = false;  // The session is no longer valid 
        ... 
    } 
    

    그리고 Global.asax에있는

    protected void Session_End(Object sender, EventArgs e) 
    { 
        Session["IsValid"] = false;  // Invalidate the session here too 
    } 
    
    
    protected void Application_AcquireRequestState(Object sender, EventArgs e) 
    { 
        if (Request.IsAuthenticated &&       // The cookie tells that the request is authenticated... 
         !(bool) HttpContext.Current.Session["IsValid"])  // but the session status is NOT valid 
        { 
          // Handle requests that re-use the auth cookie 
        } 
    } 
    
    [ASP.Net 아이덴티티 아웃 (
    관련 문제