user3738424
user3738424

Reputation: 1

Broken links of files in <img> tag ASP.NET

I'm working on a asp.net project in Visual Studio 2012. This site is contains of download section and picture galleries. I'm using such code to show pictures added into a gallery.

 string tag = "<img src=\"{0}\" width=\"64\" height=\"64\" /><br />";
                addedPics.InnerHtml += string.Format(
                    tag, Request.Url.Authority + "/admin/pictures/" + fileName);

which results in tag like below

<img src="localhost:49179/admin/pictures/sandbox_01_ME.jpg" width="64" height="64" />

before this I used code like below in a Asp:Repeater:

<img src="<%# Request.Url.Authority + "/admin/Pictures/" + Eval("Filename") %>" 
                         style="float: left" width="64" height="64" />

but neither of them is working.

Any help would be appreciated.

Upvotes: 0

Views: 56

Answers (1)

TheNorthWes
TheNorthWes

Reputation: 2739

Use a relative links in the images.

<img src="/admin/pictures/sandbox_01_ME.jpg" width="64" height="64" />

Code should be like this:

<img src="<%# "/admin/Pictures/" + Eval("Filename") %>" 
                         style="float: left" width="64" height="64" />

When you run locally, you will have trouble trying to build the absolute URL.

Upvotes: 2

Related Questions