using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.IO;
public class Handler2 : IHttpHandler {
public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "image/gif";
string connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["pppConnectionString"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand("select images from my_images where imageid = @Id",connection);
command.Parameters.Add(new SqlParameter("@Id",context.Request.QueryString["id"]));
try
{
command.Connection.Open();
SqlDataReader reader = command.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
byte[]binaryImage = (byte[])dt.Rows[0][0];
reader.Close();
context.Response.BinaryWrite(binaryImage);
}
catch(Exception ex)
{
throw ex;
}
finally
{
command.Connection.Close();
}
}
public bool IsReusable {
get {
return false;
}
}
}