I am trying to set up a page gate in Kentico. Should I look in to using a web part or a module? I have played around with both before so know how to do basic development using them.
Asked
Active
Viewed 225 times
1 Answers
1
I have done it using a Page Template before. It is actually quite simple. Facebook has a parameter 'signed_request' that is base64 encoded that it sends back (if you have an app setup in Facebook). You need to decode it and look for the 'liked' variable using json, which should be true or false.
I have a 2 CMSEditableRegion's on the page, one if a user Like's the page, one if the user has not ( yet ;) Liked the page.
protected CMSEditableRegion likedRegion;
protected CMSEditableRegion notLikedRegion;
protected bool ValidateSignedRequest(string signed_request)
{
try
{
string payload = signed_request.Split('.')[1];
UTF8Encoding encoding = new UTF8Encoding();
var decodedJson = payload.Replace("=", string.Empty).Replace('-', '+').Replace('_', '/');
var base64JsonArray = Convert.FromBase64String(decodedJson.PadRight(decodedJson.Length + (4 - decodedJson.Length % 4) % 4, '='));
var json = encoding.GetString(base64JsonArray);
return json.IndexOf("\"liked\":true") != -1;
}
catch (Exception ex)
{
return false;
}
}
private bool parsePageSignedRequest()
{
if (Request["signed_request"] != null)
{
return ValidateSignedRequest(Request["signed_request"]);
}
return false;
}
protected void Page_Load(object sender, EventArgs e)
{
if (CMS.CMSHelper.CMSContext.ViewMode == CMS.PortalEngine.ViewModeEnum.LiveSite)
{
if (parsePageSignedRequest())
{
notLikedRegion.Visible = false;
likedRegion.Visible = true;
}
else
{
notLikedRegion.Visible = true;
likedRegion.Visible = false;
}
}
}

Ben E G
- 971
- 8
- 16