2014-10-10 3 views
1

사용자가 설정을 변경할 수있는 모양을 제어하는 ​​'UI'설정이 있지만 쿠키를 업데이트해야합니다.C# 사용자가 로그인하지 않고 쿠키를 업데이트하십시오.

업데이트 할 수있는 것 같지만 사용자가 다시 인증하도록해야합니다. 사용자에게 다시 인증을 부여하지 않고 쿠키를 업데이트하려면 어떻게해야합니까?

//We need to update the userToken as the menuOptionChanged 
      var usertoken2 = new UserToken(schedule.MinimisedMenuBool); 
      HttpCookie cookie = FormsAuthentication.GetAuthCookie(usertoken.UserName, false); 
      var ticket = FormsAuthentication.Decrypt(cookie.Value); 

      var newticket = new FormsAuthenticationTicket(ticket.Version,ticket.Name,ticket.IssueDate,ticket.Expiration,false,usertoken2.CalculateRawToken(),ticket.CookiePath); 

      // Encrypt the ticket and store it in the cookie 
      cookie.Value = FormsAuthentication.Encrypt(newticket); 
      System.Web.HttpContext.Current.Response.Cookies.Set(cookie); 

답변

1

인증 쿠키에 UI ​​모양 기본 설정을 저장하는 이유는 무엇입니까?

쿠키를 별도의 쿠키로 저장하는 데 문제가 있습니까?

HttpCookie menuCookie = new HttpCookie("menuCookie");  

menuCookie.Values.Add("menuAppearance", schedule.MinimisedMenuBool); 
menuCookie.Expires = DateTime.Now.AddYears(1); 

Response.Cookies.Add(menuCookie); 

그런 다음 선택적으로 로그인 한 사용자의 쿠키 만 구문 분석 할 수 있습니다.

+0

좋은 점은, 그런 생각조차하지 못했습니다. –

관련 문제