ASP.net Generic handler

coolchamp

New Member
I'm trying pass some parameters to generic handler and get and image on response.I'm using this code for image on my web page :\[code\]<a href="http://stackoverflow.com/questions/14509564/#"><img id="slide-3" src="http://stackoverflow.com/questions/14509564/~/Image_Handler.ashx?SL=/SL1&US=Kim&ID=1 alt="Tulips" title="Tulips" /></a>\[/code\]When my page loads the image does not load. however, I put a button on my webpage and gave the same url to the PostBackUrl and it opens a new window and shows the picture totally OK.Here is my Image_handler code (generic handler)\[code\]using System;using System.Collections.Generic;using System.Configuration;using System.Data;using System.Data.SqlClient;using System.Web;namespace WEB_2._0_Programing.Private{/// <summary>/// Summary description for Image_Handler/// </summary>public class Image_Handler : IHttpHandler{ public void ProcessRequest(HttpContext context) { String id; String Slideshow = context.Request.QueryString["SL"]; String Username = context.Request.QueryString["US"]; id = context.Request.QueryString["ID"]; if (Slideshow != null) { SqlConnection connection = new SqlConnection("Data Source=KAMY-WIN7\\SQLEXPRESS;Initial Catalog=MainDataBase;Integrated Security=True;Pooling=False"); String query = "SELECT identity(int,1,1) ID,Image into #temp FROM UserImage where (Username = @username) AND (Slideshow = @slideshow) SELECT * FROM #temp WHERE (ID=@id)"; SqlCommand command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@username", Username); command.Parameters.AddWithValue("@slideshow", Slideshow); command.Parameters.Add("@id", SqlDbType.Int).Value = http://stackoverflow.com/questions/14509564/int.Parse(id); //command.Parameters.Add("@id", SqlDbType.Int).Value = http://stackoverflow.com/questions/14509564/id; connection.Open(); SqlDataReader dReader = command.ExecuteReader(); dReader.Read(); context.Response.ContentType ="image/jpeg"; Byte[] Image = (Byte[])dReader["Image"]; context.Response.BinaryWrite(Image); dReader.Close(); connection.Close(); } context.Response.Write("NOT OK!!!"); } public bool IsReusable { get { return true; } }}\[/code\]}the error on this part is that on the page load context.Request.QueryString[]; doesn't return any value but when i use a button and give the same src it works fine..Please help i have no idea what is the problem.
 
Back
Top