ASP.NET - Using a Thumbnail (ashx) to display an image on an Image Control inside a Grid

Hi experts,

I am using a thumbnail (ashx) to display an image on an image control inside a grid. I am using the following line.

ImageUrl='<%# "../../" & DataBinder.Eval(Container.DataItem, "product_image") %>'

This line works fine, however, if I send the grid html by email to all users, they receive it but dont receive the image. I tried replacing that line of code with the following, but it didnt work. It even stopped showing the image in the grid itself:

ImageUrl='<%#Server.MapPath("") + "/" + DataBinder.Eval(Container.DataItem, "product_image")%>'

What would be the problem? Is it the thumbnail itself, or the path or what exactly?
feesuAsked:
Who is Participating?
 
jorge_torizResearch & Development ManagerCommented:
You have a double slash after the port: "http://<domain name>:80//", remove one.
0
 
jorge_torizResearch & Development ManagerCommented:
You must use the full URI, append "http://www.yoursite.com/" + Eval("product_image")

Something like that.
0
 
feesuAuthor Commented:
jorge,

1- Will this work with a thumbnail?
2- If I manually write the full URI how would I run it on my test environment?

Thanks,
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
KinjalKumar PatelSenior Software EngineerCommented:
Jorge,

For the test environment you can have some sort of enum created within the application that helps you to identify globally in your application that from which domain you are running the application. Depending on the domain the URL needs to be set.

Hope this may help you.

Thanks
0
 
jorge_torizResearch & Development ManagerCommented:
This will work with your thumbnail too.

I wrote "you must use the full URI" because you asked why the HTML doesn't work when you send it to the people you want, and without a full URI won't work, but, if you want to see your pics only in your page you shouldn't append the full URI.
0
 
feesuAuthor Commented:
jorge,

I want this to work on the live website plus on my development PC. Is that possible?
0
 
jorge_torizResearch & Development ManagerCommented:
Yes, take out my comment about appending your full URI, just use the Eval function to get you image name and thats all, I work in this way to show images in the development and production state.
0
 
feesuAuthor Commented:
You mean not to use the thumbnail anymore?
0
 
jorge_torizResearch & Development ManagerCommented:
I would use something like this:

ImageUrl='<%# ResolveClientUrl("~/imgProducts/") + Eval("product_image").ToString().Replace(".jpg", "_thumbnail.jpg") %>'

I suppose that your product has a thumbnail with the same name but with a postfix "_thumbnail"
0
 
feesuAuthor Commented:
jorge,

My code at design time looks like:

--------------------------------------------------------------------------------------------------------------------------------
<rad:GridTemplateColumn Groupable="False" UniqueName="ProductImage" HeaderText="IMAGE">
                    <ItemTemplate>
                        <asp:Image
                            ID="ShoppingImg" runat="server" Height="25"
                            ImageUrl='<%# "../../" + DataBinder.Eval(Container.DataItem, "product_image")%>'
                           
                            Width="25" />
                       
                    </ItemTemplate>
                    <HeaderStyle Width="30px" />
                    <ItemStyle Height="36px" HorizontalAlign="Center" VerticalAlign="Middle" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" Wrap="True" />
                </rad:GridTemplateColumn>
--------------------------------------------------------------------------------------------------------------------------------





And at run-time, this is how it looked like:

--------------------------------------------------------------------------------------------------------------------------------
<img id="ctl13_gridShoppingCart_ctl01_ctl04_ShoppingImg" src="DesktopModules/Products/Thumb.ashx?ImgPath=Files\Products\pPOLO2-6714648_standard_v330.jpg&amp;MaxHeight=250&amp;MaxWidth=230" style="height:25px;width:25px;border-width:0px;" />
--------------------------------------------------------------------------------------------------------------------------------
0
 
jorge_torizResearch & Development ManagerCommented:
And?, what do you get?, first of all the imgPath its wrong, you must use "/", but leaving this out... what do you get?

I would prefer to store in the database the value "pPOLO2-6714648_standard_v330.jpg", the width and the height in separated columns to build up the right path at runtime with the RowDataBound event.
0
 
feesuAuthor Commented:
1- I get the image properly at runtime, but when I send the html by email, it shows "X" instead of the image.
2- I am using thumbs to pass the height/width parameters at rum time because I am using the images in different places with different sizes, I cannot save all these sizes inside the database. In order to do that I will have to do a major change to my structure.

What exactly is my problem to show the image on the recipient's email? What do I need to chage?
0
 
jorge_torizResearch & Development ManagerCommented:
Before "DesktopModules/Products/Thumb.aspx" concatenate the full URL of that handler, like:

"http://www.mysample.com/DesktopModules/Products/Thumb.aspx"
0
 
feesuAuthor Commented:
Great, how can I do that by code, taking into account that I don't want to hard code the full URL because I want the project to work properly on the development machine as well?
0
 
jorge_torizResearch & Development ManagerCommented:
With Request.Url.Host you get the domain name, then add "http://" before that
0
 
feesuAuthor Commented:
This is my image line in the aspx, I think I did something wrong because the image stopped showing:

<asp:Image ID="ShoppingImg" runat="server" Height="25"
ImageUrl='<%# "http://" + Request.Url.Host + "/" + DataBinder.Eval(Container.DataItem, "product_image")%>'
Width="25" />
0
 
jorge_torizResearch & Development ManagerCommented:
In your development environment the Request.Url.Host shows "localhost:port" but it will never give you the folder where your application is running, then in the development machine you won't see your image.

Other thing that you can do is create a protected property in your page that returns the Request.Url.Host when is in published but when is in development will return your "localhost:port/App" path.
0
 
feesuAuthor Commented:
Well localhost:port will be enough, but this is not happening. It is showing localhost only without the port!
0
 
jorge_torizResearch & Development ManagerCommented:
Append the port with the Request.Url.Port property
0
 
feesuAuthor Commented:
I did that. But still facing a problem. The image is not showing. Let me check if there is something else that needs to be changed.
0
 
feesuAuthor Commented:
I was not able to find anything.
I deployed the site and placed the order, and received the email. The email image source is as below:

http://<domain name>:80//DesktopModules/Products/Thumb.ashx?ImgPath=Files/Products/p758_DSC_4009.jpg&amp;MaxHeight=250&amp;MaxWidth=230

This is as per your recommendation, it is not working!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.