using System; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.PortalEngine; public partial class CMSWebParts_General_SetCookie : CMSAbstractWebPart { #region "Public properties" /// /// Name of the cookie. /// public string Name { get { return ValidationHelper.GetString(GetValue("Name"), ""); } set { SetValue("Name", value); } } /// /// Value of the cookie. /// public string CookieValue { get { return ValidationHelper.GetString(GetValue("CookieValue"), ""); } set { SetValue("CookieValue", value); } } /// /// Expiration time of the cookie. /// public DateTime Expiration { get { return ValidationHelper.GetDateTimeSystem(GetValue("Expiration"), DateTime.MaxValue); } set { SetValue("Expiration", value); } } /// /// The virtual path to transmit with the cookie. /// public string Path { get { return ValidationHelper.GetString(GetValue("Path"), ""); } set { SetValue("Path", value); } } #endregion #region "Page events" /// /// Loads the web part content. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } #endregion #region "Other methods" /// /// Sets up the control. /// protected void SetupControl() { if (StopProcessing) { // Do nothing } else { if (CMSContext.ViewMode == ViewModeEnum.LiveSite) { // Length of the string in the cookie, because size of the cookie can't be more than 4KB int length = Name.Length + CookieValue.Length + Path.Length + Expiration.ToString().Length; if ((Name != "") && (length < 4000)) { CookieHelper.SetValue(Name, CookieValue, Path, Expiration); } } } } #endregion }