-
Notifications
You must be signed in to change notification settings - Fork 1
/
ImageHandler6.ashx
40 lines (32 loc) · 1.24 KB
/
ImageHandler6.ashx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<%@ WebHandler Language="C#" Class="ImageHandler" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
public class ImageHandler : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
SqlConnection con = new SqlConnection();
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings
["ConnectionString"].ConnectionString;
// Create SQL Command
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Select image from [Album] where id=@id and album=@album";
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(context.Request.QueryString["ImID"]);
cmd.Parameters.Add("@album", SqlDbType.NVarChar, 100).Value = context.Request.QueryString["album"];
con.Open();
SqlDataReader dReader = cmd.ExecuteReader();
dReader.Read();
context.Response.BinaryWrite((byte[])dReader["image"]);
dReader.Close();
con.Close();
}
public bool IsReusable {
get {
return false;
}
}
}