Beispiel #1
0
 static void Pipeline_Rewrite(IHttpModule sender, HttpContext context, IUrlEventArgs e)
 {
     if (e.VirtualPath.StartsWith(PathUtils.ResolveAppRelative("~/photos/"), StringComparison.OrdinalIgnoreCase))
     {
         e.VirtualPath = PathUtils.ResolveAppRelative("~/App_Data/") + e.VirtualPath.Substring(PathUtils.AppVirtualPath.Length).TrimStart('/');
     }
 }
Beispiel #2
0
 void Pipeline_PostRewrite(IHttpModule sender, HttpContext context, IUrlEventArgs e)
 {
     // Server-side cachebreaker
     if (e.QueryString["red_dot"] != "true" && ShouldWatermark())
     {
         e.QueryString["red_dot"] = "true";
     }
 }
Beispiel #3
0
        private void Pipeline_Rewrite(IHttpModule sender, HttpContext context, IUrlEventArgs e)
        {
            if (e.VirtualPath == null)
            {
                context.RewritePath("index.html");
            }

            string fileCache = ImageHelper.checkFile(e.VirtualPath);

            context.RewritePath(fileCache);



            //string root = ConfigurationManager.AppSettings["ImageRoot"] ?? String.Empty;


            //root = "~/upload/";
            //var test = VirtualPathUtility.ToAbsolute(root);
            //if (e.VirtualPath.StartsWith(VirtualPathUtility.ToAbsolute(root), StringComparison.OrdinalIgnoreCase))
            //{
            //    e.VirtualPath = Regex.Replace(e.VirtualPath,
            //        string.Format("/{root}/img/([0-9]+)\\.([0-9]+)-([^/]+)\\.(jpg|jpeg|png|gif)"),
            //        delegate(Match match)
            //        {
            //            e.QueryString["width"] = match.Groups[1].Value;
            //            e.QueryString["height"] = match.Groups[2].Value;
            //            e.QueryString["mode"] = "scale";
            //            return string.Format("/{root}/img/{match.Groups[3].Value}.{match.Groups[4].Value}");
            //        });
            //    //e.VirtualPath = Regex.Replace(e.VirtualPath, string.Format("/{root}/img/([0-9]+)w-([^/]+)\\.(jpg|jpeg|png|gif)"),
            //    //    delegate(Match match)
            //    //    {
            //    //        e.QueryString["width"] = match.Groups[1].Value;
            //    //        e.QueryString["mode"] = "scale";
            //    //        return string.Format("/{root}/img/{match.Groups[2].Value}.{match.Groups[3].Value}");
            //    //    });
            //    //e.VirtualPath = Regex.Replace(e.VirtualPath, string.Format("/{root}/img/([0-9]+)h-([^/]+)\\.(jpg|jpeg|png|gif)"),
            //    //    delegate(Match match)
            //    //    {
            //    //        e.QueryString["height"] = match.Groups[1].Value;
            //    //        e.QueryString["mode"] = "scale";
            //    //        return string.Format("/{root}/img/{match.Groups[2].Value}.{match.Groups[3].Value}");
            //    //    });

            //    context.RewritePath(e.VirtualPath);

            //}
            //else {
            //    //using V308CMS.Static.Helpers;

            //    string fileCache = ImageHelper.checkFile(e.VirtualPath);
            //    context.RewritePath(fileCache);
            //    //var fInfo = new System.IO.FileInfo(e.VirtualPath);
            //    //var result = fInfo.DirectoryName;

            //}
        }
        private void OnRewriteDefaults(IHttpModule sender, HttpContext context, IUrlEventArgs e)
        {
            var preset = e.QueryString["preset"];

            if (!string.IsNullOrWhiteSpace(preset) && !_presetNames.Contains(preset.ToLowerInvariant()))
            {
                throw new HttpException(404, "Not Found");
            }
            ServiceLocator.Current.GetInstance <IContentHashHelper>().RedirectIfWrongHash(new HttpContextWrapper(context), ServiceLocator.Current.GetInstance <IContentRouteHelper>().Content);
        }
Beispiel #5
0
 private void Pipeline_Rewrite(IHttpModule sender, HttpContext context, IUrlEventArgs e)
 {
     if (e.VirtualPath.StartsWith("/globalassets/catalogs/", StringComparison.OrdinalIgnoreCase) &&
         e.QueryString["preset"] == null &&
         e.QueryString["Height"] == null &&
         e.QueryString["Width"] == null)
     {
         e.QueryString["Height"] = "500";
         e.QueryString["Width"]  = "500";
         e.QueryString["scale"]  = "both";
     }
 }
Beispiel #6
0
        private static string GetCacheKeyForUrl(IUrlEventArgs urlEventArgs, ResizeSettings resizeSettings)
        {
            var keyBuilder = new StringBuilder();

            keyBuilder.Append("focalpoint:");
            keyBuilder.Append(urlEventArgs.VirtualPath);
            keyBuilder.Append(":");
            foreach (var key in resizeSettings.AllKeys)
            {
                keyBuilder.AppendFormat("{0}:{1}", key, resizeSettings[key]);
            }
            return(keyBuilder.ToString());
        }
        void Pipeline_RewriteDefaults(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
        {
            ///Handle redirectThrough behavior
            if (redirectThrough != null && context.Items[c.Pipeline.ModifiedPathKey + ".hadquery"] != null) {
                //It had a querystring originally - which means the request didn't come from CloudFront, it came directly from the browser. Perform a redirect, rewriting the querystring appropriately
                string finalPath = redirectThrough + e.VirtualPath + PathUtils.BuildSemicolonQueryString(e.QueryString, true);

                //Redirect according to setting
                context.Response.Redirect(finalPath, !redirectPermanent);
                if (redirectPermanent) {
                    context.Response.StatusCode = 301;
                    context.Response.End();
                }
            }
        }
Beispiel #8
0
        private void ApplyFocalPointCropping(IUrlEventArgs urlEventArgs)
        {
#if DEBUG
            var stopWatch = new Stopwatch();
            stopWatch.Start();
#endif
            try {
                var resizeSettings = GetResizeSettingsFromQueryString(urlEventArgs.QueryString);
                if (resizeSettings == null)
                {
                    return;
                }
                var cacheKey       = GetCacheKeyForUrl(urlEventArgs, resizeSettings);
                var cropParameters = this.cache.Get(cacheKey) as string;
                if (cropParameters == null)
                {
                    Logger.Debug($"Crop parameters not found in cache for '{urlEventArgs.VirtualPath}'.");
                    var currentContent = ServiceLocator.Current.GetInstance <IContentRouteHelper>().Content;
                    if (currentContent != null)
                    {
                        var evictionPolicy = GetEvictionPolicy(currentContent.ContentLink);
                        var focalPointData = currentContent as IFocalPointData;
                        if (focalPointData?.FocalPoint != null && focalPointData.ShouldApplyFocalPoint(resizeSettings))
                        {
                            Logger.Debug($"Altering resize parameters for {focalPointData.Name} based on focal point.");
                            cropParameters = CropDimensions.Parse(focalPointData, resizeSettings).ToString();
                            this.cache.Insert(cacheKey, cropParameters, evictionPolicy);
                        }
                        else
                        {
                            Logger.Debug($"No focal point set for '{currentContent.Name}'.");
                            this.cache.Insert(cacheKey, string.Empty, evictionPolicy);
                        }
                    }
                }
                if (!string.IsNullOrWhiteSpace(cropParameters))
                {
                    urlEventArgs.QueryString.Add("crop", cropParameters);
                }
            } catch (Exception ex) {
                Logger.Critical("A critical error occured when trying to get focal point data.", ex);
            }
#if DEBUG
            stopWatch.Stop();
            Logger.Debug($"{nameof(ApplyFocalPointCropping)} for {urlEventArgs.VirtualPath} took {stopWatch.ElapsedMilliseconds}ms.");
#endif
        }
Beispiel #9
0
 void ApplyPreset(IUrlEventArgs e, Dictionary <string, ResizeSettings> dict)
 {
     if (!string.IsNullOrEmpty(e.QueryString["preset"]))
     {
         string[] presets = e.QueryString["preset"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
         foreach (string p in presets)
         {
             if (!dict.ContainsKey(p))
             {
                 continue;
             }
             ResizeSettings query = dict[p];
             foreach (string key in query.Keys)
             {
                 e.QueryString[key] = query[key];
             }
         }
     }
 }
        private void Pipeline_PostRewrite(IHttpModule sender, HttpContext context, IUrlEventArgs e)
        {
            HttpRequest httpRequest = HttpContext.Current.Request;

            // If resolution of current screen has been passed, set maxwidth 
            // parameter for ImageResizer to handle in its pipeline
            HttpCookie httpCookie = httpRequest.Cookies.Get(ResolutionCookieKey);

            if (httpCookie != null)
            {
                e.QueryString.Add("maxwidth", httpCookie.Value);
            }

            // A cookie has not been set. If current user agent is identified 
            // as a mobile device, serve the smallest image
            else if (httpRequest.UserAgent.ToLower().Contains(UserAgentMobileSubstring))
            {
                string width = _resolutions[_resolutions.Length - 1];
                e.QueryString.Add("maxwidth", width);
            }
        }
Beispiel #11
0
        /*<resizer>
         * <watermarks>
         *  <otherimages path="~/watermarks" align="topleft" width="50%" />
         *  <group name="wmark">
         *   <image path="~/watermarks/image.png" align="topleft" width="50px" height="50px" />
         *  </group>
         */
        //top, left, bottom, right = px or percentages (relative to container)
        //relativeTo = image|imageArea|padding|border|margin|canvas
        //drawAs overlay|background
        //image
        //imagesettings
        //align = topleft|topright|bottomleft|bottomright|...

        void Pipeline_PostRewrite(IHttpModule sender, HttpContext context, IUrlEventArgs e)
        {
            //Cache breaking
            string[] parts = WatermarksToUse(e.QueryString);
            if (parts == null)
            {
                return;
            }

            foreach (string w in parts)
            {
                if (NamedWatermarks.ContainsKey(w))
                {
                    IEnumerable <Layer> layers = NamedWatermarks[w];
                    foreach (Layer l in layers)
                    {
                        e.QueryString["watermark-cachebreak"] = (e.QueryString["watermark-cachebreak"] ?? "") + "_" + l.GetDataHash().ToString();
                    }
                }
            }
        }
        private void ApplyFocalPointCropping(IUrlEventArgs urlEventArgs)
        {
            var focalPointData = urlResolver.Route(new UrlBuilder(urlEventArgs.VirtualPath)) as IFocalPointData;

            if (focalPointData?.FocalPoint != null)
            {
                var resizeSettings = GetResizeSettingsFromQueryString(urlEventArgs.QueryString);
                if (!ShouldCrop(focalPointData, resizeSettings))
                {
                    return;
                }
                Logger.Information($"Altering resize parameters for {focalPointData.Name} based on focal point.");
                var cacheKey       = GetCacheKeyForResize(focalPointData.ContentLink, resizeSettings);
                var cropParameters = cache.Get(cacheKey) as string;
                if (cropParameters == null)
                {
                    cropParameters = GetCropDimensions(focalPointData, resizeSettings).ToString();
                    cache.Insert(cacheKey, cropParameters, GetEvictionPolicy(focalPointData.ContentLink));
                }
                urlEventArgs.QueryString.Add("crop", cropParameters);
            }
        }
Beispiel #13
0
        void Pipeline_Rewrite(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
        {
            var os = provider.GetOverlays(e.VirtualPath, e.QueryString);
            if (os == null) return;

            long hash = 0xab224895;
            int offset = 0;
            foreach (Overlay o in os) {
                int ohash = o.GetDataHashCode();
                string physicalPath = HostingEnvironment.MapPath(o.OverlayPath);
                try{
                    ohash ^= (int)(File.GetLastWriteTimeUtc(physicalPath).Ticks / (TimeSpan.TicksPerMillisecond * 5));
                }catch{}
                hash ^= ohash << (offset % 50);
                offset += 31;
            }
            //Store a hash of all the overlays, so the disk cache updates when an overlay changes
            e.QueryString["customoverlay.hash"] = hash.ToString();

            //And save the overlays for later
            RequestOverlays = os;
        }
Beispiel #14
0
 void PipelineConfig_RewriteDefaults(IHttpModule sender, HttpContext context, IUrlEventArgs e)
 {
     e.QueryString = e.QueryString.MergeDefaults(pipelineDefaults);
 }
Beispiel #15
0
 void Pipeline_PostRewrite(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     if (e.QueryString["preset"] != null) e.QueryString.Remove("preset"); //Remove presets so they aren't processed again during ModifySettings
 }
Beispiel #16
0
        /// <summary>
        /// Returns true if the specified querystring and file will cause a PNG file to be returned.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        private bool DestFormatPng(IUrlEventArgs e)
        {
            IEncoder guessedEncoder = c.Plugins.GetEncoder(new ResizeSettings(e.QueryString), e.VirtualPath);

            return(guessedEncoder != null && "image/png".Equals(guessedEncoder.MimeType, StringComparison.OrdinalIgnoreCase));
        }
Beispiel #17
0
 void Pipeline_PostRewrite(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     if (IsRemotePath(e.VirtualPath))
     {
         //Force images to be processed - don't allow them to only cache it.
         e.QueryString["process"] = ProcessWhen.Always.ToString().ToLowerInvariant();
     }
 }
Beispiel #18
0
 void Pipeline_Rewrite(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     if (OnlyAllowPresets) {
         e.QueryString = FilterQuerystring(e.QueryString, false);
     }
     ApplyPreset(e, settings);
 }
Beispiel #19
0
 void ApplyPreset(IUrlEventArgs e, Dictionary<string, ResizeSettings> dict)
 {
     if (!string.IsNullOrEmpty(e.QueryString["preset"])) {
         string[] presets = e.QueryString["preset"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
         foreach (string p in presets) {
             if (!dict.ContainsKey(p)) continue;
             ResizeSettings query = dict[p];
             foreach (string key in query.Keys) {
                 e.QueryString[key] =query[key];
             }
         }
     }
 }
Beispiel #20
0
        void Pipeline_Rewrite(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
        {
            var os = provider.GetOverlays(e.VirtualPath, e.QueryString);

            if (os == null)
            {
                return;
            }

            long hash   = 0xab224895;
            int  offset = 0;

            foreach (Overlay o in os)
            {
                int    ohash        = o.GetDataHashCode();
                string physicalPath = HostingEnvironment.MapPath(o.OverlayPath);
                try{
                    ohash ^= (int)(File.GetLastWriteTimeUtc(physicalPath).Ticks / (TimeSpan.TicksPerMillisecond * 5));
                }catch {}
                hash   ^= ohash << (offset % 50);
                offset += 31;
            }
            //Store a hash of all the overlays, so the disk cache updates when an overlay changes
            e.QueryString["customoverlay.hash"] = hash.ToString();

            //And save the overlays for later
            RequestOverlays = os;
        }
Beispiel #21
0
        /*<resizer>
         * <watermarks>
         *  <otherimages path="~/watermarks" align="topleft" width="50%" />
         *  <group name="wmark">
         *   <image path="~/watermarks/image.png" align="topleft" width="50px" height="50px" />
         *  </group>
         */
        //top, left, bottom, right = px or percentages (relative to container)
        //relativeTo = image|imageArea|padding|border|margin|canvas
        //drawAs overlay|background
        //image
        //imagesettings
        //align = topleft|topright|bottomleft|bottomright|...
        void Pipeline_PostRewrite(IHttpModule sender, HttpContext context, IUrlEventArgs e)
        {
            //Cache breaking
            string[] parts = WatermarksToUse(e.QueryString);
            if (parts == null) return;

            foreach (string w in parts)
            {
                if (NamedWatermarks.ContainsKey(w))
                {
                    IEnumerable<Layer> layers = NamedWatermarks[w];
                    foreach (Layer l in layers)
                    {
                        e.QueryString["watermark-cachebreak"] = (e.QueryString["watermark-cachebreak"] ?? "") + "_" + l.GetDataHash().ToString();
                    }
                }
            }
        }
Beispiel #22
0
 void Pipeline_RewriteDefaults(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     //Set the XXX of /remote.XXX to the real extension used by the remote file.
     //Allows the output extension and mime-type default to be determined correctly
     if (IsRemotePath(e.VirtualPath) &&
             !string.IsNullOrEmpty(e.QueryString[Base64UrlKey])) {
         string ext = PathUtils.GetExtension(PathUtils.FromBase64UToString(e.QueryString[Base64UrlKey]));
         if (!string.IsNullOrEmpty(ext) && c.Pipeline.IsAcceptedImageType("." + ext))
             e.VirtualPath = PathUtils.SetExtension(e.VirtualPath, ext);
     }
 }
Beispiel #23
0
 void Pipeline_PostRewrite(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     if (e.QueryString["preset"] != null)
     {
         e.QueryString.Remove("preset");                                  //Remove presets so they aren't processed again during ModifySettings
     }
 }
Beispiel #24
0
 void Pipeline_Rewrite(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     if (OnlyAllowPresets)
     {
         e.QueryString = FilterQuerystring(e.QueryString, false);
     }
     ApplyPreset(e, settings);
 }
Beispiel #25
0
 void Pipeline_RewriteDefaults(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     ApplyPreset(e, defaults);
 }
Beispiel #26
0
        public void FireRewritingEvents(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
        {
            //TODO: this approach is non-intuitive....

            //Fire first event (results will stay in e)
            if (Rewrite != null)
            {
                Rewrite(sender, context, e);
            }

            //Copy querystring for use in 'defaults' even
            NameValueCollection copy = new NameValueCollection(e.QueryString); //Copy so we can later overwrite q with the rewrite values.

            //Fire defaults event.
            if (RewriteDefaults != null)
            {
                RewriteDefaults(sender, context, e);
            }

            //Overwrite with querystring values again - this is what makes applyDefaults applyDefaults, vs. being applyOverrides.
            foreach (string k in copy)
            {
                if (copy[k] != null)   //Don't allow null values to override defaults. Empty values can, however.
                {
                    e.QueryString[k] = copy[k];
                }
            }

            //Fire final event
            if (PostRewrite != null)
            {
                PostRewrite(sender, context, e);
            }
        }
Beispiel #27
0
 void Pipeline_PostRewrite(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     if (IsRemotePath(e.VirtualPath)) {
         //Force images to be processed - don't allow them to only cache it.
         e.QueryString["process"] = ProcessWhen.Always.ToString().ToLowerInvariant();
     }
 }
Beispiel #28
0
 public void FireImageMissing(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     if (ImageMissing != null)
     {
         ImageMissing(sender, context, e);
     }
 }
Beispiel #29
0
 public void FireImageMissing(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     if (ImageMissing != null) ImageMissing(sender, context, e);
 }
Beispiel #30
0
 void Pipeline_RewriteDefaults(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     //Set the XXX of /remote.XXX to the real extension used by the remote file.
     //Allows the output extension and mime-type default to be determined correctly
     if (IsRemotePath(e.VirtualPath) &&
         !string.IsNullOrEmpty(e.QueryString[Base64UrlKey]))
     {
         string ext = PathUtils.GetExtension(PathUtils.FromBase64UToString(e.QueryString[Base64UrlKey]));
         if (!string.IsNullOrEmpty(ext) && c.Pipeline.IsAcceptedImageType("." + ext))
         {
             e.VirtualPath = PathUtils.SetExtension(e.VirtualPath, ext);
         }
     }
 }
Beispiel #31
0
        public void FireRewritingEvents(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
        {
            //TODO: this approach is non-intuitive....

            //Fire first event (results will stay in e)
            if (Rewrite != null) Rewrite(sender,context, e);

            //Copy querystring for use in 'defaults' even
            NameValueCollection copy = new NameValueCollection(e.QueryString); //Copy so we can later overwrite q with the rewrite values.

            //Fire defaults event.
            if (RewriteDefaults != null) RewriteDefaults(sender, context, e);

            //Overwrite with querystring values again - this is what makes applyDefaults applyDefaults, vs. being applyOverrides.
            foreach (string k in copy) {
                if (copy[k] != null) { //Don't allow null values to override defaults. Empty values can, however.
                    e.QueryString[k] = copy[k];
                }
            }

            //Fire final event
            if (PostRewrite != null) PostRewrite(sender,context, e);
        }
Beispiel #32
0
 static void Pipeline_Rewrite(IHttpModule sender, HttpContext context, IUrlEventArgs e)
 {
     if (e.VirtualPath.StartsWith(PathUtils.ResolveAppRelative("~/photos/"), StringComparison.OrdinalIgnoreCase))
         e.VirtualPath = PathUtils.ResolveAppRelative("~/App_Data/") + e.VirtualPath.Substring(PathUtils.AppVirtualPath.Length).TrimStart('/');
 }
Beispiel #33
0
 /// <summary>
 /// Returns true if the specified querystring and file will cause a PNG file to be returned.
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 private bool DestFormatPng(IUrlEventArgs e)
 {
     IEncoder guessedEncoder = c.Plugins.GetEncoder(new ResizeSettings(e.QueryString), e.VirtualPath);
     return  (guessedEncoder != null && "image/png".Equals(guessedEncoder.MimeType, StringComparison.OrdinalIgnoreCase));
 }
Beispiel #34
0
 private void PipelineRewriteDefaults(IHttpModule sender, HttpContext context, IUrlEventArgs e)
 {
     ApplyFocalPointCropping(e);
 }
Beispiel #35
0
 void Pipeline_RewriteDefaults(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     ApplyPreset(e, defaults);
 }
Beispiel #36
0
 /// <summary>
 /// We duplicate efforts in PostRewrite to ensure that the DiskCache doesn't block configuration changes.
 /// This won't help CloudFront, however.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="context"></param>
 /// <param name="e"></param>
 void Pipeline_PostRewrite(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     e.QueryString = Modify(new ResizeSettings(e.QueryString));
 }
 /// <summary>
 /// We duplicate efforts in PostRewrite to ensure that the DiskCache doesn't block configuration changes. 
 /// This won't help CloudFront, however.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="context"></param>
 /// <param name="e"></param>
 void Pipeline_PostRewrite(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
 {
     e.QueryString = Modify(new ResizeSettings(e.QueryString));
 }
Beispiel #38
0
        /*<resizer>
         * <watermarks>
         *  <otherimages path="~/watermarks" align="topleft" width="50%" />
         *  <group name="wmark">
         *   <image path="~/watermarks/image.png" align="topleft" width="50px" height="50px" />
         *  </group>
         */
        //top, left, bottom, right = px or percentages (relative to container)
        //relativeTo = image|imageArea|padding|border|margin|canvas
        //drawAs overlay|background
        //image
        //imagesettings
        //align = topleft|topright|bottomleft|bottomright|...
        void Pipeline_PostRewrite(IHttpModule sender, HttpContext context, IUrlEventArgs e)
        {
            //Cache breaking
            string watermark = e.QueryString["watermark"]; //from the querystring
            if (string.IsNullOrEmpty(watermark)) return;

            string[] parts = watermark.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string w in parts)
            {
                if (NamedWatermarks.ContainsKey(w))
                {
                    IEnumerable<Layer> layers = NamedWatermarks[w];
                    foreach (Layer l in layers)
                    {
                        e.QueryString["watermark-cachebreak"] = (e.QueryString["watermark-cachebreak"] ?? "") + "_" + l.GetDataHash().ToString();
                    }
                }
            }
        }
Beispiel #39
0
        void Pipeline_RewriteDefaults(System.Web.IHttpModule sender, System.Web.HttpContext context, IUrlEventArgs e)
        {
            ///Handle redirectThrough behavior
            if (redirectThrough != null && context.Items[c.Pipeline.ModifiedPathKey + ".hadquery"] != null)
            {
                //It had a querystring originally - which means the request didn't come from CloudFront, it came directly from the browser. Perform a redirect, rewriting the querystring appropriately
                string finalPath = redirectThrough + e.VirtualPath + PathUtils.BuildSemicolonQueryString(e.QueryString, true);

                //Redirect according to setting
                context.Response.Redirect(finalPath, !redirectPermanent);
                if (redirectPermanent)
                {
                    context.Response.StatusCode = 301;
                    context.Response.End();
                }
            }
        }