1

나는 잠시 동안 이걸로 싸워 왔습니다. VS 2012에서는 "인터넷 응용 프로그램"프로젝트 템플릿을 사용하여 새로운 MVC4 응용 프로그램을 만들었습니다 (간단히하기 위해 ExtendedMembershipProvider를 사용하는 일반 응용 프로그램에서도 문제가 발생합니다). 로그인에FormsAuthentication은 UserData를 기본 MVC4 웹 응용 프로그램 템플릿에 저장하지 않습니다.

나는 폼 인증 쿠키 일부 UserData를 데려 가고 싶다는, 그래서 나는 다음 코드를 사용합니다

public ActionResult Login(LoginModel model, string returnUrl) 
{ 
    Request.Cookies.Remove(FormsAuthentication.FormsCookieName); 
    if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) 
    { 
     HttpCookie authCookie = FormsAuthentication.GetAuthCookie(model.UserName, true); 
     string userData = "This is some test data."; 
     FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); 
     FormsAuthenticationTicket newAuthTicket = new FormsAuthenticationTicket(authTicket.Version, authTicket.Name, authTicket.IssueDate, authTicket.Expiration, authTicket.IsPersistent, userData); 
     string newAuthTicketEncrypted = FormsAuthentication.Encrypt(newAuthTicket); 
     authCookie.Value = newAuthTicketEncrypted; 

     Request.Cookies.Set(authCookie); 
     // Response.Write("Encrypted cookie value: " + authCookie.Value); // value here differs than what browser sees 
     // Response.Write("UserData: " + FormsAuthentication.Decrypt(authCookie.Value).UserData + "<br/>"); // userdata is present here. 
     // return, shortened for brevity 

    } 

} 

예쁜 기본입니다. 그러나 쿠키를 해독 할 때 쿠키에 존재하지 않습니다. 문제는 뭔가가 파이프 라인의 다른 곳에서 새로운 폼 인증 쿠키를 만드는 것입니다. 암호화 된 쿠키의 값을 출력하고 로그인 요청 후 브라우저에 나타나는 값과 비교하여이를 증명할 수 있습니다. 그들은 다르다! 뭔가 UserData가없는 상태에서 쿠키를 다시 만들고 암호화합니다. 이름 값은 쿠키에 존재합니다 - 어떤 일을하고 있는지 또는 어떤 일을하고 있는지 알 수 있습니까? MS가 새로운 WebMatrix 메소드로 양식 인증에서 UserData를 중단 했습니까?

+0

안녕하세요 !!! 마침내 너를 위해 일 했니? – akjha627

답변

3

응답 개체에 쿠키를 설정해야하는 요청에 쿠키를 설정하고 있습니다.

+0

와우 - 나는 그것을 보지 못했다고 나는 믿을 수 없다. 멍청한 실수. –

관련 문제