GetImage.ashx
<%@ WebHandler Language="C#" Class="GetImage" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Data.Sql;
public class GetImage : IHttpHandler {
public void ProcessRequest (HttpContext context) {
using (SqlConnection sc = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
{
sc.Open();
String txtsql = "select photo from employees where employeeid=" + context.Request.QueryString["eid"];
SqlCommand scd = new SqlCommand(txtsql, sc);
context.Response.Clear();
context.Response.ContentType = "image/bmp";
byte[] bitmapBytes = (byte[])scd.ExecuteScalar();
int length = bitmapBytes.Length;
context.Response.OutputStream.Write(bitmapBytes, 78, bitmapBytes.Length - 78);
context.Response.Cache.SetCacheability(HttpCacheability.Public);
}
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}