Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 04, 2013 01:16 PM by eric2820
Dec 31, 2012 12:24 PM|LINK
byte buffer = null;
string querySqlStr = "";
if (context.Request.QueryString["ImageID"] != null)
querySqlStr = "select * from tbPicUser where userID=" + context.Request.QueryString["ImageID"];
querySqlStr = "select * from tbPicUser";
SqlConnection con = new SqlConnection(@"Data Source=L4037\SQLSERVEREXPRESS;Initial Catalog=DatingWS;Integrated Security=True");
SqlCommand cmd = new SqlCommand(querySqlStr, con);
SqlDataReader reader = cmd.ExecuteReader();
buffer = (byte)reader["picData"];
context.Response.ContentType = "image/jpg";
in my c# file
pnImage.Controls.Add(new LiteralControl("<img src=imgHandler.ashx?ImageID=1 alt=\"\" Width=\"300\" Height=\"200\" />"));
I get an empty image box.
Can any one help?
Dec 31, 2012 04:31 PM|LINK
shouldn't the src attribute have quotes around it?
pnImage.Controls.Add(new LiteralControl("<img src=\"imgHandler.ashx?ImageID=1\" alt=\"\" Width=\"300\" Height=\"200\" />"));
Another thing to check is to see if your handler is working properly. Manually type in that path into your browser and see if you get the expected image.
Dec 31, 2012 04:40 PM|LINK
I've added the quotes and still the same result. The handler works if I write it in the browser.
Dec 31, 2012 04:46 PM|LINK
Are we looking at a pathing/routing issue? Maybe the relative pathing isn't working properly? Do you have Chrome? The inspector has some useful tools to examine downloaded resources and http requests.
Dec 31, 2012 05:46 PM|LINK
I am using Chrome.
I will try the Chrome inspector.
Dec 31, 2012 08:57 PM|LINK
I realy need some help on this please
Dec 31, 2012 09:11 PM|LINK
Since it is properly displaying when you type the handler into the URL bar, but not when being placed in an image, I can only assume that perhaps it is a relative pathing issue. Is your handler located in the same directory as the aspx/html page that has
this image tag?
Jan 01, 2013 06:29 AM|LINK
yes the file is located in the same folder. Should it be someware else?
Jan 01, 2013 02:57 PM|LINK
It appears that I found that I need to register the handler in the web.config file.
in the <system.web> i've put :
<add verb="*" path="*.ashx" type="dating2.imgHandler"/>
and in the <system.webServer> i've put:
<add verb="*" path="*.ashx"
I also put the ashx file in the app_data folder.
I still don't see the image on my page. I still get an empty image box.
I don't know what to test anymore. i'm realy stuck.
Jan 02, 2013 03:13 PM|LINK
I've never implemented an image handler, just a file handler to allow download of recognized mime types. It's gonna come down to figuring out where the break is occuring. Since you have verified that typing the handler address directly into the browser
yields the expected image, the problem lies in the link from the image tag. At this point, if it were my debug, I would try manually writing an img tag into the markup (versus through a literal) just to make sure it isn't being somehow modified in the transition
from server to client. I don't think we'll see anything different, but it's just to cross off another possibility.