Saluti!ASPX che restituisce un'immagine - Output Cache-capable?
Ho creato un modulo Web APSX che restituisce un'immagine remota in base ad alcuni parametri forniti. Può essere utilizzato in questo modo: markup e codice
<img src="/ImageGetter.aspx?param1=abc¶m2=123" />
di ImageGetter.aspx simile al seguente:
<%@ OutputCache Duration="100000" VaryByParam="*" Location="ServerAndClient" %>
<%@ Page Language="C#" AutoEventWireup="false" EnableSessionState="False" CodeBehind="ImageGetter.aspx.cs" Inherits="ACME.Helpers.ImageGetter" %>
Questo codice è chiamato nel metodo Page_Load di ImageGetter.aspx:
byte[] data = null;
Dictionary<string, string> file_locations = GetImageLocations(param1, param2);
try
{
data = new WebClient().DownloadData(file_locations["main"]);
}
catch (WebException wex)
{
try
{
data = new WebClient().DownloadData(file_locations["backup"]);
}
catch (Exception e)
{
throw;
}
}
Response.ContentType = "image/jpeg";
Response.OutputStream.Write(data, 0, data.Length);
Response.End();
Dai miei test, non sembra essere il caching. È possibile farlo con Output Caching o dovrei ricorrere alla scrittura della mia cache per archiviare gli array di byte in base ai parametri della stringa di query?
Dropping Response.End rallenta qualche giù ancora di più. – Bullines
... perché ora sta saltando attraverso i cerchi della cache? – Codebrain