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.
"Dream as if you'll live forever, live as if you'll die today." --James Dean
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.
"Dream as if you'll live forever, live as if you'll die today." --James Dean
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?
"Dream as if you'll live forever, live as if you'll die today." --James Dean
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.
"Dream as if you'll live forever, live as if you'll die today." --James Dean
Rimo72
Member
2 Points
18 Posts
image will not display
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"]; } else { querySqlStr = "select * from tbPicUser"; } SqlConnection con = new SqlConnection(@"Data Source=L4037\SQLSERVEREXPRESS;Initial Catalog=DatingWS;Integrated Security=True"); con.Open(); SqlCommand cmd = new SqlCommand(querySqlStr, con); try { SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { buffer = (byte[])reader["picData"]; context.Response.Clear(); context.Response.ContentType = "image/jpg"; context.Response.BinaryWrite(buffer); context.Response.Flush(); context.Response.Close(); } reader.Close(); } finally { con.Close(); }in my c# file
void GetImagesFromDatabase() { pnImage.Controls.Add(new LiteralControl("<div>")); pnImage.Controls.Add(new LiteralControl("<img src=imgHandler.ashx?ImageID=1 alt=\"\" Width=\"300\" Height=\"200\" />")); pnImage.Controls.Add(new LiteralControl("</div>")); }I get an empty image box.
Can any one help?
Thanks
AceCorban
Star
12358 Points
2274 Posts
Re: image will not display
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.
Rimo72
Member
2 Points
18 Posts
Re: image will not display
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.
AceCorban
Star
12358 Points
2274 Posts
Re: image will not display
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.
Rimo72
Member
2 Points
18 Posts
Re: image will not display
Dec 31, 2012 05:46 PM|LINK
I am using Chrome.
I will try the Chrome inspector.
Rimo72
Member
2 Points
18 Posts
Re: image will not display
Dec 31, 2012 08:57 PM|LINK
I realy need some help on this please
AceCorban
Star
12358 Points
2274 Posts
Re: image will not display
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?
Rimo72
Member
2 Points
18 Posts
Re: image will not display
Jan 01, 2013 06:29 AM|LINK
yes the file is located in the same folder. Should it be someware else?
Rimo72
Member
2 Points
18 Posts
Re: image will not display
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 :
<httpHandlers> <add verb="*" path="*.ashx" type="dating2.imgHandler"/> </httpHandlers>and in the <system.webServer> i've put:
<handlers> <add verb="*" path="*.ashx" name="imgHandler" type="dating2.imgHandler"/> </handlers>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.
Any suggestion?
AceCorban
Star
12358 Points
2274 Posts
Re: image will not display
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.