2012-10-25 3 views
1

을 설정하는 컨트롤러에 AffiliateLogin 함수가 있습니다.
principal.User = user;은 실제로 프린시 펄을 저장하는 행입니다. 그러나 다른 컨트롤러로 리디렉션 한 후 내 AuthorizeWithRolesAttribute 특성을 테스트하면 보안 주체가 재설정됩니다.
이는 로그인 후 1 초, 당신은 빨간색 화살표를 볼 수 있습니다한 요청 후에 주체가 손실됩니다.

enter image description here

이 그것을 저장하는 기능입니다.
내가 뭘 잘못하고 있니?
감사

public JsonResult AffiliateLogin(string email, string password) 
     { 
      if (ModelState.IsValid) 
      { 
       Affiliate user = api.GetUserByCredencials<Affiliate>(email, password); 
       if (user != null) 
       { 

        IIdentity identity = new UserIdentity(true,user.Email); 
        UserPrincipal principal = new UserPrincipal(identity, new string[] {"Affiliate"}); 
        principal.User = user; 

        HttpContext.User = principal; 
        return Json("Login success"); 
       } 
      } 
      return Json("Fail To Login"); 
     } 
+0

라고 AffiliateLogin된다 배울 수있는 좋은 장소가 여기에

var principal = ClaimsPrincipal.Current; //normally this reverts to Thread.CurrentPrincipal, 

을 확인할 수 있습니까? – ChrisBint

+0

@ChrisBint - 해당 동작 : localhost : 5555/Api/User/AffiliateLogin /? [email protected]&password=pass – SexyMF

답변

0

주요 속성은 웹 요청 사이에서 살아남지 못할 것이다. 재 지정 후 다음 요청에서 다시 설정해야합니다. 당신은 사용자 정의 인증/폼 인증을 수행하고있는 경우

+0

설명해주십시오. 나는 문단의 범위가 요청 당 – SexyMF

+0

을 거역하지 않습니다. 그래서 각 요청은 새로운'httpcontext'입니다. –

+0

@JasonMeckley - 해결책은 무엇입니까 – SexyMF