API Questions on Kentico API.
Version 5.x > API > CookieHelper.ChangeCookieExpiration from static method View modes: 
User avatar
Member
Member
gatsby0121 - 6/28/2011 9:13:44 AM
   
CookieHelper.ChangeCookieExpiration from static method
Is there any way to call this method from a static method?

User avatar
Guest
kentico_michal - 7/1/2011 2:44:52 AM
   
RE:CookieHelper.ChangeCookieExpiration from static method
Hello,

Could please describe this issue in more detail? Do you encounter any problem when executing this method? The CookieHelper.ChangeCookieExpiration method is a static method, so it should be possible to call it without any problems.

Best regards,
Michal Legen

User avatar
Guest
gatsby0121 - 7/4/2011 5:49:02 AM
   
RE:CookieHelper.ChangeCookieExpiration from static method
Turns out that issue was something else which I fixed. But for some reason when I call the method, it runs, but when I close the browser and go back to the page, I'm logged out.

This is the code I'm using:

// Set view mode to live site after login to prevent bar with "Close preview mode"
CMSContext.ViewMode = CMS.PortalEngine.ViewModeEnum.LiveSite;

// Ensure response cookie
CookieHelper.EnsureResponseCookie(FormsAuthentication.FormsCookieName);



if (Membership.ValidateUser(userEmail, customerPwd))
{
FormsAuthentication.SetAuthCookie(userEmail, false);
CMS.GlobalHelper.RequestStockHelper.Remove("CurrentUser");
CMS.GlobalHelper.RequestStockHelper.Add("CurrentUser", new CMS.CMSHelper.CurrentUserInfo(ui, true));
}

// Set cookie expiration
if (RememberMeSet)
{
CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddYears(1), false);
}
else
{
FormsAuthentication formAuth = new FormsAuthentication();
// Extend the expiration of the authentication cookie if required
if (!UserInfoProvider.UseSessionCookies && (HttpContext.Current != null) && (HttpContext.Current.Session != null))
{
CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddMinutes(HttpContext.Current.Session.Timeout), false);
}
}

User avatar
Member
Member
kentico_michal - 7/11/2011 6:28:27 AM
   
RE:CookieHelper.ChangeCookieExpiration from static method
Hello,

I have tested this method and it worked as expected.

Could you please check what is the cookie expiration after CookieHelper.ChangeCookieExpiration method gets executed.

What browser do you use? Could you please make sure that cookie is enabled in the browser?

Best regards,
Michal Legen