Greetings!
I've created an APSX web form that returns a remote image based on some supplied parameters. It can be used like this:
<img src="/ImageGetter.aspx?param1=abc¶m2=123" />
ImageGetter.aspx's markup and code look similar to this:
<%@ OutputCache Duration="100000" VaryByParam="*" Location="ServerAndClient" %>
<%@ Page Language="C#" AutoEventWireup="false" EnableSessionState="False" CodeBehind="ImageGetter.aspx.cs" Inherits="ACME.Helpers.ImageGetter" %>
This code is called in ImageGetter.aspx's Page_Load method:
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();
From my testing, it doesn't appear to be caching. Is this possible to do with Output Caching or should I resort to writing my own cache to store the byte arrays depending on query string paramters?