2016-08-01 5 views
0

Identity Framework로 ASP.Net 응용 프로그램을 만들었습니다. 사용자 인증이 성공적으로 System.Web.HttpContext.Current.User.Identitynull하고 System.Web.HttpContext.Current.User.Identity.IsAuthenticatedfalse로그인 인증 후 사용자가 Null입니다.

public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) 
    { 
     if (!ModelState.IsValid) 
     { 
      return View(model); 
     } 
     var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: true); 
     switch (result) 
     { 
      case SignInStatus.Success: 
       ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); 
       UserManager.AddClaim(User.Identity.GetUserId(),new Claim(ClaimTypes.Role,"Admin")); 

후 나는 인증 후 인증 된 사용자에게 어떤 역할을 추가해야합니다.

+0

첫 번째 리디렉션 후에 만 ​​사용자 ID를 얻을 수 있습니다 – anand

답변

4

처음으로 리디렉션이 발생하면 User.Identity.GetUserId()에 값을 얻을 수 있습니다. 리다이렉션하자마자. 그러면 쿠키가 생성되고 User.Identity.GetUserId() 또는 User.Identity.IsAuthenticated을 사용합니다.

+0

어떤 장소 (기능/클래스)에서 인증 된 사용자에게 역할을 할당 할 수 있습니까? – Sami

+0

@Sami : 로그인 후 역할을 지정하는 이유. 그것은 Db에 저장되어야합니다. –

관련 문제