Skip to content

Instantly share code, notes, and snippets.

@islaytitans
Created June 30, 2016 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save islaytitans/e442f33a2b77d4d26417472c667c61ed to your computer and use it in GitHub Desktop.
Save islaytitans/e442f33a2b77d4d26417472c667c61ed to your computer and use it in GitHub Desktop.
Sitecore Personalization rule for levelled gated access
public class GrantGatedAccessLevelledCondition<T> : IntegerComparisonCondition<T> where T : RuleContext
{
public int No { get; set; }
...
protected override bool Execute(T ruleContext)
{
string cookieName = Utility.DefineCookieName();
if (HttpContext.Current.Request.Cookies[cookieName] == null)
return false;
var actualLevel = HttpContext.Current.Request.Cookies[cookieName].Value;
if (string.IsNullOrEmpty(actualLevel))
return false;
int actualLevelInt;
if (!int.TryParse(actualLevel, out actualLevelInt))
return false;
Value = No;
return Compare(actualLevelInt);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment