public string GetCdnOrNormalUrl(string mediaUrl, MediaItem item)
        {
            //Preview in Master can load CDN
            if (cdnHelper.CanUseCdnForMedia(item))
            {
                var cdnDomainUrl = cdnHelper.GetCdnDomainUrl();
                if (string.IsNullOrEmpty(cdnDomainUrl))
                {
                    return(mediaUrl);
                }

                if (Uri.TryCreate(new Uri(cdnDomainUrl), cdnHelper.GetCdnRelativePathForItem(item), out Uri op))
                {
                    return(op.ToString());
                }
            }
            return(mediaUrl);
        }
Exemple #2
0
        private void ProcessCdnRedirect(HttpContext context, Media media)
        {
            var item = media?.MediaData?.MediaItem?.InnerItem;

            if (cdnHelper.CanUseCdnForMedia(item))
            {
                var cdnDomainUrl = cdnHelper.GetCdnDomainUrl();

                if (!string.IsNullOrEmpty(cdnDomainUrl))
                {
                    if (Uri.TryCreate(new Uri(cdnDomainUrl), cdnHelper.GetCdnRelativePathForItem(item), out Uri op))
                    {
                        HttpContext.Current.Response.RedirectPermanent(cdnHelper.BuildCdnUrlWithQueryString(op.ToString(),
                                                                                                            context.Request.QueryString.ToString(), item.GetFieldValue(Helper.Constants.MediaTemplateFields.UpdatedOn)), true);
                    }
                }
            }
        }