Ejemplo n.º 1
0
        private void CreatedVirtualPath(object sender, UrlBuilderEventArgs urlBuilderEventArgs)
        {
            var cdnConfiguration = CdnConfigurationSection.GetConfiguration();

            var originalPath = urlBuilderEventArgs.UrlBuilder.Path;

            if (originalPath.StartsWith(cdnConfiguration.AdminPath))
            {
                return;
            }

            var enabled = cdnConfiguration.Enabled;

            if (!enabled)
            {
                return;
            }

            object contentReferenceObject;

            if (!urlBuilderEventArgs.RouteValues.TryGetValue(RoutingConstants.NodeKey, out contentReferenceObject))
            {
                return;
            }

            var routedContentLink = contentReferenceObject as ContentReference;

            if (ContentReference.IsNullOrEmpty(routedContentLink))
            {
                return;
            }

            // Check content type is Image or not
            var imageData = DataFactory.Instance.Get <IContent>(routedContentLink) as ImageData;

            if (imageData == null)
            {
                return;
            }

            // Check access rights
            var securable = imageData as ISecurable;

            if ((securable.GetSecurityDescriptor().GetAccessLevel(PrincipalInfo.AnonymousPrincipal) & AccessLevel.Read) != AccessLevel.Read)
            {
                return;
            }

            var baseUrl = CdnConfigurationSection.GetConfiguration().Url;

            if (string.IsNullOrWhiteSpace(baseUrl))
            {
                baseUrl = SiteDefinition.Current.SiteUrl.AbsoluteUri;
            }

            urlBuilderEventArgs.UrlBuilder.Uri = new Uri(string.Format("{0}/{1}", baseUrl.TrimEnd('/'), originalPath.TrimStart('/')));
        }
Ejemplo n.º 2
0
        private void OnBeginRequest(object sender, EventArgs e)
        {
            var url = HttpContext.Current.Request.Url.AbsoluteUri;
            var cdnConfiguration = CdnConfigurationSection.GetConfiguration();

            if (string.IsNullOrEmpty(cdnConfiguration.Url) || !url.StartsWith(cdnConfiguration.Url))
            {
                return;
            }
            HttpContext.Current.Items[CdnConfigurationSection.GetConfiguration().ItemKey] = true;
        }
Ejemplo n.º 3
0
        protected override void SetCachePolicy(HttpContextBase context, DateTime fileChangedDate)
        {
            var isCdnRequest = HttpContext.Current.Items[CdnConfigurationSection.GetConfiguration().ItemKey];

            if (isCdnRequest == null || !(bool)isCdnRequest)
            {
                base.SetCachePolicy(context, fileChangedDate);
                return;
            }

            fileChangedDate = fileChangedDate > DateTime.UtcNow ? DateTime.UtcNow : fileChangedDate;

            context.Response.Cache.SetLastModified(fileChangedDate);
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.Cache.SetExpires(DateTime.UtcNow.AddYears(1));
            context.Response.Cache.SetValidUntilExpires(true);
            context.Response.Cache.VaryByParams.IgnoreParams = true;
            context.Response.Cache.SetOmitVaryStar(true);
            context.Response.Cache.SetNoServerCaching();
        }