void Pipeline_Rewrite(IHttpModule sender, HttpContext context, Configuration.IUrlEventArgs e) { //Remove 'iefix' immediately if it's not relevant so we don't slow down static requests or do needless re-encoding. if (!NeedsPngFix(context)) { e.QueryString.Remove("iefix"); } }
void Pipeline_RewriteDefaults(IHttpModule sender, HttpContext context, Configuration.IUrlEventArgs e) { //If this is IE 6 or earlier, and catchall is enabled, add iefix=true to all requests, regardless of (current) file type. //Rewriting rules may change the format or add it later, we'll filter to just PNG requests in PostRewrite. if (NeedsPngFix(context) && CatchAll) { e.QueryString["iefix"] = "true"; //If CatchAll is enabled, it's a png, and we set the default value here. } }
/// <summary> /// In case there is no querystring attached to the file (thus no operations on the fly) we can /// redirect directly to the blob. This let us take advantage of the CDN (if configured). /// </summary> /// <param name="sender"></param> /// <param name="context"></param> /// <param name="e"></param> void Pipeline_PostRewrite(IHttpModule sender, HttpContext context, Configuration.IUrlEventArgs e) { string prefix = vpp.VirtualFilesystemPrefix; // Check if prefix is within virtual file system and if there is no querystring if (e.VirtualPath.StartsWith(prefix, StringComparison.OrdinalIgnoreCase) && e.QueryString.Count == 0) { // Strip prefix from virtual path; keep container and blob string relativeBlobURL = e.VirtualPath.Substring(prefix.Length).TrimStart('/', '\\'); // Redirect to blob context.Response.Redirect(blobStorageEndpoint + relativeBlobURL); } }
/// <summary> /// In case there is no querystring attached to the file (thus no operations on the fly) we can /// redirect directly to the blob. This let us offload traffic to blob storage /// </summary> /// <param name="sender"></param> /// <param name="context"></param> /// <param name="e"></param> void Pipeline_PostRewrite(IHttpModule sender, HttpContext context, Configuration.IUrlEventArgs e) { string prefix = VirtualFilesystemPrefix; // Check if prefix is within virtual file system and if there is no querystring if (RedirectToBlobIfUnmodified && Belongs(e.VirtualPath) && !c.Pipeline.HasPipelineDirective(e.QueryString)) { // Strip prefix from virtual path; keep container and blob string relativeBlobURL = e.VirtualPath.Substring(prefix.Length).TrimStart('/', '\\'); // Redirect to blob //TODO: Add shared access signature if enabled context.Response.Redirect(blobStorageEndpoint + relativeBlobURL); } }
void Pipeline_PostRewrite(IHttpModule sender, HttpContext context, Configuration.IUrlEventArgs e) { if (e.QueryString.Get("iefix", false) && NeedsPngFix(context) && DestFormatPng(e)) { if (Redirect) { //Get the original request URL, and change the 'format' setting to 'gif'. NameValueCollection newValues = new NameValueCollection(); newValues["format"] = "gif"; context.Response.Redirect(PathUtils.MergeOverwriteQueryString(context.Request.RawUrl, newValues), true); } else { e.QueryString["format"] = "gif"; } } e.QueryString.Remove("iefix"); }
void Pipeline_RewriteDefaults(System.Web.IHttpModule sender, System.Web.HttpContext context, Configuration.IUrlEventArgs e) { //Handles /resize(width,height,format)/ and /resize(width,height)/ syntaxes. e.VirtualPath = parseResizeFolderSyntax(e.VirtualPath, e.QueryString); }
void Pipeline_ImageMissing(System.Web.IHttpModule sender, System.Web.HttpContext context, Configuration.IUrlEventArgs e) { if (!string.IsNullOrEmpty(e.QueryString["404"])) { //Resolve the path to virtual or app-relative for string path = resolve404Path(e.QueryString["404"]); //Resolve to virtual path path = Util.PathUtils.ResolveAppRelative(path); // Merge commands from the 404 querystring with ones from the // original image. We start by sanitizing the querystring from // the image. ResizeSettings imageQuery = new ResizeSettings(e.QueryString); imageQuery.Normalize(); // Use the configured settings by default. var filterMode = this.filterMode; var except = this.except; // To support querystring-specifiable filter mode and exceptions, // uncomment the if block below. ////// If the imageQuery includes specific 404 command-filtering, ////// (*either* of the values), use those instead of the ////// configured defaults. ////if (!string.IsNullOrEmpty(e.QueryString["404.filterMode"]) || //// !string.IsNullOrEmpty(e.QueryString["404.except"])) ////{ //// filterMode = NameValueCollectionExtensions.Get(e.QueryString, "404.filterMode", FilterMode.ExcludeUnknownCommands); //// except = MatcherCollection.Parse(e.QueryString["404.except"]); ////} // remove all of the commands we're supposed to remove... we // clone the list of keys so that we're not modifying the collection // while we enumerate it. var shouldRemove = CreateRemovalMatcher(filterMode, except); var names = new List <string>(imageQuery.AllKeys); foreach (var name in names) { if (shouldRemove(name, imageQuery[name])) { imageQuery.Remove(name); } } // Always remove the '404', '404.filterMode', and '404.except' settings. imageQuery.Remove("404"); imageQuery.Remove("404.filterMode"); imageQuery.Remove("404.except"); ResizeSettings i404Query = new ResizeSettings(Util.PathUtils.ParseQueryString(path)); i404Query.Normalize(); //Overwrite new with old foreach (string key in i404Query.Keys) { if (key != null) { imageQuery[key] = i404Query[key]; } } path = PathUtils.AddQueryString(PathUtils.RemoveQueryString(path), PathUtils.BuildQueryString(imageQuery)); //Redirect context.Response.Redirect(path, true); } }
void Pipeline_RewriteDefaults(System.Web.IHttpModule sender, System.Web.HttpContext context, Configuration.IUrlEventArgs e) { //Only works with blob provided files //Non-images will be served as-is //Cache all file types, whether they are processed or not. if (CacheUnmodifiedFiles && Belongs(e.VirtualPath)) { e.QueryString["cache"] = ServerCacheMode.Always.ToString(); } }
void Pipeline_PostRewrite(System.Web.IHttpModule sender, System.Web.HttpContext context, Configuration.IUrlEventArgs e) { //Only work with database images //If the data is untrusted, always re-encode each file. if (UntrustedData && Belongs(e.VirtualPath)) { e.QueryString["process"] = ImageResizer.ProcessWhen.Always.ToString(); } }
void Pipeline_Rewrite(System.Web.IHttpModule sender, System.Web.HttpContext context, Configuration.IUrlEventArgs e) { string file = Path.GetFileName(e.VirtualPath); if (activeFilenames.Contains(file)) { string filePhysicalPath = PathUtils.MapPathIfAppRelative("~" + e.VirtualPath); if (!File.Exists(filePhysicalPath)) { string physicalDirPath = Path.GetDirectoryName(filePhysicalPath); string[] files = Directory.GetFiles(physicalDirPath, "*.jpg", SearchOption.TopDirectoryOnly); if (files.Length > 0) { Random r = new Random(); int index = r.Next(0, files.Length); file = files[index]; string newVirtualPath = Path.GetDirectoryName(e.VirtualPath).Replace("\\", "/") + "/" + Path.GetFileName(file); e.VirtualPath = newVirtualPath; } else { string fallback = c.get("folderThumb.default", ""); e.VirtualPath = "/images/" + fallback; } if (e.QueryString.Count == 0) { var col = new NameValueCollection(); col.Add("fthumb", "true"); e.QueryString.Add(col); } } } }
void Pipeline_ImageMissing(System.Web.IHttpModule sender, System.Web.HttpContext context, Configuration.IUrlEventArgs e) { if (!string.IsNullOrEmpty(e.QueryString["404"])) { //Resolve the path to virtual or app-relative for string path = resolve404Path(e.QueryString["404"]); //Resolve to virtual path path = Util.PathUtils.ResolveAppRelative(path); //Merge commands from the 404 querystring with ones from the original image. ResizeSettings imageQuery = new ResizeSettings(e.QueryString); imageQuery.Normalize(); imageQuery.Remove("404"); //Remove the 404 ref ResizeSettings i404Query = new ResizeSettings(Util.PathUtils.ParseQueryString(path)); i404Query.Normalize(); //Overwrite new with old foreach (string key in i404Query.Keys) { if (key != null) { imageQuery[key] = i404Query[key]; } } path = PathUtils.AddQueryString(PathUtils.RemoveQueryString(path), PathUtils.BuildQueryString(imageQuery)); //Redirect context.Response.Redirect(path, true); } }