Created
July 29, 2021 10:28
-
-
Save gerhart92/414fdf50e1654baee6a297384149898b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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