Click here to Skip to main content
12,890,954 members (58,468 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
I have Image control,Database containing id,name and image.,and i hve created a handler name picview.ashx.Picview.ashx loads images from database but only first image in column is displayed.In ashx file if i write where clause and give a specific Id then another image is displayed.i want to display image according to the id which is holded by cookie.*how to do retrieve value of cookie in select statement on ashx file??*so that it can display images according to id.
picview code is as follows:-
<%@ WebHandler Language="C#" Class="picview" %>
using System;
using System.Web;
using System.Data.SqlClient;
public class picview : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "image/jpeg";
        int id = Convert.ToInt32(context.Request.QueryString["ImageID"]);
        string cmdText = "SELECT Pic FROM Profile";//here i want to retrieve cookie value.
        string myConnection = "Data Source=AOD257;Initial Catalog=EduSocial;User Id=sa;Password=password";
        SqlConnection connection = new SqlConnection(myConnection);
        SqlCommand command = new SqlCommand(cmdText, connection);
        SqlDataReader reader = command.ExecuteReader();
        byte[] image = (byte[])reader[0];
    public bool IsReusable {
        get {
            return true;

Code behind page
private void GetImageFromDatabase(int ID)
       Image1.ImageUrl = "picview.ashx"+ID.ToString();
Posted 6-Dec-12 4:26am
Updated 6-Dec-12 6:24am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You would be able to get the id in query string, only issue I could notice is there is missing "?ImageID=" while creating the url.

private void GetImageFromDatabase(int ID)
       Image1.ImageUrl = "picview.ashx"+ID.ToString();

<pre lang="cs">private void GetImageFromDatabase(int ID)
       Image1.ImageUrl = "picview.ashx?ImageID="+ID.ToString();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100