Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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" %>
C#
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);
        connection.Open();

        SqlDataReader reader = command.ExecuteReader();
        reader.Read();
        byte[] image = (byte[])reader[0];
        context.Response.BinaryWrite(image);
        reader.Close();
        connection.Close();
       
    }
 
    public bool IsReusable {
        get {
            return true;
        }
    }

}

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

1 solution

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.

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


XML
<pre lang="cs">private void GetImageFromDatabase(int ID)
   {
       Image1.ImageUrl = "picview.ashx?ImageID="+ID.ToString();
   }</pre>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900