Executing Select Commands
<%@ Page Language="C#" %>
Photo Gallery
File: Web.config
File: DynamicImage.ashx
<%@ WebHandler Language="C#" Class="DynamicImage" %>
using System.Data;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
public class DynamicImage : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
string imageId = context.Request.QueryString["Id"];
SqlDataSource src = new SqlDataSource();
src.ConnectionString = WebConfigurationManager.ConnectionStrings ["Images"].ConnectionString;
src.SelectCommand = "SELECT Image FROM Images WHERE Id=" + imageId;
DataView view = (DataView)src.Select(DataSourceSelectArguments.Empty);
context.Response.BinaryWrite( (byte[])view[0]["Image"]);
}
public bool IsReusable
{
get {
return false;
}
}
}