Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8382427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:55:34+00:00 2026-06-09T16:55:34+00:00

I have written the following handler class which is used to read images from

  • 0

I have written the following handler class which is used to read images from database and show them in my web page :

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

using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Web;

public class Handler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["IranQRDBConnectionString"].ConnectionString);
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            string TableName = context.Session["TableToQuery"].ToString();
            string ID = context.Session["ID"].ToString();

            SqlCommand comm = new SqlCommand("SELECT * FROM " + TableName + " WHERE ID=" + ID, conn);

            conn.Open();
            SqlDataReader dr = comm.ExecuteReader();
            dr.Read();
            context.Response.ContentType = "image/jpeg";
            context.Response.BinaryWrite((byte[])dr["Image"]);
            conn.Close();

        }
        catch
        {
            SqlCommand comm = new SqlCommand("SELECT * FROM DefaultImage WHERE ID=1", conn);

            conn.Open();
            SqlDataReader dr = comm.ExecuteReader();
            dr.Read();
            context.Response.ContentType = "image/jpeg";
            context.Response.BinaryWrite((byte[])dr["Image"]);
            conn.Close();
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}

This class works fine on my local ! I have uploaded my website and when I query my database all data is returned to my web page except the image is not shown in the image control. I have searched the web and I found out that I should register my handler in the web.config file and also IIS version is 7 on the host and It’s running in integrated mode ! So I know that I should register that handler in <System.webserver><Handlers> part of the web.config .

For more detail I added the handler class to my project root directory and not in the App_Code directory ! And I have uploaded the website as precompiled website and I have the precompiled Handler.ashx in my root directory and I have App_Web_handler.ashx.cdcab7d2.dll file in my App_Code .

I also have added :

<add name="ImageHandler" verb="*" path="*.jpg" type="Handler" />

in my web.config file but it still does not work 🙁

Could any one help please me find the correct registration ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:55:35+00:00Added an answer on June 9, 2026 at 4:55 pm

    And here comes the answer ! there was nothing wrong with my code , and there was a firewall on the host wich did not allow my images to be showen ! after configuring the firewall my project works just fine 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have written the following code class Program { static void Main(string[] args) {
I have written the following query, but in the WHERE clause I have used
I have written the following Utility class to get an instance of any class
I have the following service written with Delphi 2007 which I find is not
I have written the following code in MATLAB to process large images of the
I have a form_for written in the following manner: <div class=field> <%= location.label :city
I have written a custom route handler. Because I have Areas in my web
I've written the following custom Exception handler: namespace System\Exception; class Handler extends \Exception {
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
I am trying my hands on WPF MVVM. I have written following code in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.