Click here to Skip to main content
14,271,317 members
Rate this:
Please Sign up or sign in to vote.
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" %>
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
private void GetImageFromDatabase(int ID)
   {
       Image1.ImageUrl = "picview.ashx"+ID.ToString();
   }
Posted
Updated 6-Dec-12 6:24am
v2

1 solution

Rate this:
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();
   }</pre>
   

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




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