Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gerhart92/414fdf50e1654baee6a297384149898b to your computer and use it in GitHub Desktop.
Save gerhart92/414fdf50e1654baee6a297384149898b to your computer and use it in GitHub Desktop.
[HttpPost]
[ValidateInput(false)]
public ActionResult DownloadGatedContent(string articleId)
{
if (!Sitecore.Context.PageMode.IsExperienceEditor)
{
HttpCookie cookie = new HttpCookie("CapcoCookie");
var userEntryId = Guid.NewGuid();
cookie["UserEntryId"] = userEntryId.ToString();
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
}
var articleItem = Sitecore.Context.Database.GetItem(articleId);
Sitecore.Data.Fields.FileField fileField = articleItem.Fields[Templates.ArticleBase.Fields.AttachmentFile];
if (fileField != null && fileField.MediaItem != null)
{
var fileUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(fileField.MediaItem);
if (!string.IsNullOrEmpty(fileUrl))
{
return Content(Sitecore.Resources.Media.HashingUtils.ProtectAssetUrl(fileUrl));
}
}
return Content(LinkManager.GetItemUrl(articleItem));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment