shilpi gupta

shilpi gupta

  • NA
  • 49
  • 71.7k

Fetch image from database using handler

Nov 24 2010 5:47 AM
hi
 i m stroing  & retriving image from database.
  i retrive image using handler than show image using gridview. but i face error



Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load type 'Handler'.

Source Error:

Line 66: </pages>
Line 67: <httpHandlers>
Line 68: <add verb="*" path="*.gif" type="Handler" />
Line 69: <remove verb="*" path="*.asmx"/>
Line 70: <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>





handler code is

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Data; //Add this namespace
using System.IO;

public class Handler : IHttpHandler {

public void ProcessRequest (HttpContext context) {
string constring = WebConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;
SqlConnection con = new SqlConnection(constring);
con.Open();
string sql = "Select image_content, type from image where image_id=@ImageId";
SqlCommand cmd = new SqlCommand(sql, myConnection);
cmd.Parameters.Add("@ImageId", SqlDbType.Int).Value = context.Request.QueryString["id"];
cmd.Prepare();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
context.Response.ContentType = dr["type"].ToString();
context.Response.BinaryWrite((byte[])dr["image_content"]);
dr.Close();
myConnection.Close();
}

public bool IsReusable {
get {
return false;
}
}

}




how to handler this error


Answers (2)