<%@ WebHandler Language="C#" Class="EventsImagesHandler" %> using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Web; public class EventsImagesHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { //context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); int id = Convert.ToInt32(context.Request.QueryString["imageid"].ToString()); Byte[] content = GetImageFromDB(id); context.Response.BinaryWrite(content); } public bool IsReusable { get { return false; } } private byte[] GetImageFromDB(int id) { SqlConnection connection = new SqlConnection(); connection.ConnectionString = @"data source=jhalakservices.cpm5bnayea5q.us-west-2.rds.amazonaws.com;Initial Catalog=Classifieds;Persist Security Info=True;User ID=Shailesh;Password=jhalak0987;"; connection.Open(); SqlCommand command = new SqlCommand("GetImage", connection); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add("Id", System.Data.SqlDbType.Int).Value = id; Byte[] content = command.ExecuteScalar() as Byte[]; connection.Close(); return content; } }