/// <summary> /// Busca o parâmetro "picture" na queryString, e trata caso exista. /// </summary> /// <param name="context"></param> private void VerificaParametro_Picture(HttpContext context) { if (!String.IsNullOrEmpty(context.Request.QueryString["picture"])) { string fileName = UtilBO.DecodificaQueryString(context.Request.QueryString["picture"]); bool redimensionar = ((!String.IsNullOrEmpty(context.Request.QueryString["w"])) && (!String.IsNullOrEmpty(context.Request.QueryString["h"]))); try { string folder = context.Server.MapPath("~/App_Themes"); FileInfo info = new FileInfo(folder + Path.DirectorySeparatorChar + fileName); if (info.Directory.FullName.StartsWith(folder, StringComparison.OrdinalIgnoreCase)) { if ((info.Exists) && IsImage(info)) { context.Response.Cache.SetCacheability(HttpCacheability.Public); context.Response.Cache.SetExpires(DateTime.Now.AddYears(1)); if (redimensionar) { int heigth = Convert.ToInt32(context.Request.QueryString["h"]); int width = Convert.ToInt32(context.Request.QueryString["w"]); Image.GetThumbnailImageAbort myCallback = ThumbnailCallback; Image img = Image.FromFile(info.FullName); // Criando objeto redimencionado. Image thumb = img.GetThumbnailImage ( width, heigth, myCallback, IntPtr.Zero ); // ContentType sempre JPG. context.Response.ContentType = "image/png"; // Enviando email para Response. thumb.Save ( context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg ); img.Dispose(); thumb.Dispose(); } else { int index = fileName.LastIndexOf(".") + 1; string extension = fileName.Substring(index).ToUpperInvariant(); // Fix for IE not handling jpg image types if (string.Compare(extension, "JPG") == 0) { context.Response.ContentType = "image/png"; } else { context.Response.ContentType = "image/" + extension; } context.Response.TransmitFile(info.FullName); } context.Response.Flush(); } else { // Limpa o response. context.Response.Flush(); context.Response.Clear(); context.ApplicationInstance.CompleteRequest(); } } else { context.Response.Redirect("~/Manutencao.aspx?erro=404", false); context.ApplicationInstance.CompleteRequest(); } } catch (Exception ex) { try { // Limpa o response. context.Response.Flush(); context.Response.Clear(); context.ApplicationInstance.CompleteRequest(); ApplicationWEB._GravaErro(ex); } catch { } } } }