2014-10-09 4 views
7

사용자를 인증하기 위해 owin 인증 관리자를 사용하려고하지만 User.Identity.IsAuthenticated는 여전히 false입니다.Owin Authentication.SignIn이 작동하지 않음

Startup.cs

public partial class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     app.MapSignalR(); 
    } 
} 

Startup.Auth.cs

public partial class Startup 
{ 
    public static Func<UserManager<ApplicationUser>> UserManagerFactory { get; set; } 

    public Startup() 
    { 
     UserManagerFactory =() => 
     { 
      var userManager = new UserManager<ApplicationUser>(new CustomUserStore()); 
      return userManager; 
     }; 
    } 

    public void ConfigureAuth(IAppBuilder app) 
    { 
     app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
      LoginPath = new PathString("/Account/Login"), 
      LogoutPath = new PathString("/Account/LogOff"), 
      ExpireTimeSpan = TimeSpan.FromDays(7) 
     }); 
    } 
} 

인증 활동의 일부 :

private async Task SignInAsync(ApplicationUser user, bool isPersistent) 
    { 
     var authManager = return HttpContext.GetOwinContext().Authentication; 
     authManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); 
     var identity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); 
     authManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, identity); 
    } 

Identity value

After sign in

ID는 성공적으로 만들어 지지만 SignIn 메서드는 사용자로 로그인하지 않습니다. 뭐가 문제 야?

+0

브라우저가 쿠키를 보냅니 까? 그것은 브라우저에 의해 보존됩니까? – trailmax

+0

@trailmax, 아니요, 쿠키가 브라우저로 전송되지 않았습니다. – Neshta

답변

6

이것은 매우 어리석은 실수입니다. 나는 ConfigureAuth 방법으로 전화하는 것을 잊었다.

public partial class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     ConfigureAuth(app); // <-- this 
     app.MapSignalR(); 
    } 
} 
관련 문제