-4
<img src="http://www.vclogos.co.uk/logo.php?subid=d18f655c3fc147&amp;imgid=11542">

The above tag shows image when i create notepad html page but when i put it on asp.net it does not show image on the browser.

Randy
  • 9,419
  • 5
  • 39
  • 56
Tabish
  • 1
  • 1
  • This is pretty broad, do you have ány idea what is going on and why it does not work? – Randy May 19 '16 at 10:19
  • I don`t know that is why i am asking it to others this url shows image on simple notepad created html page but when i put it on asp.net this is not showing image on browser :( – Tabish May 19 '16 at 10:21
  • 1
    1) Check the page source in your browser. Is the HTML tag still looking as expected there? 2) Check the browser console (press F12 and choose console tab) for any errors waiting for you there. – CherryDT May 19 '16 at 10:24
  • No console error and i check html img tag on the browser by inspect element img tag is present but not showing image . – Tabish May 19 '16 at 10:27

2 Answers2

1

It doesn't work because the server behind the URL in question checks the HTTP referer and returns an empty page if a referer is set which doesn't match the expected one.

The referer tells the "vclogos" server from which website the request for loading the image came from.

This is probably a security measure from the page because they don't want people to do what you just tried to do: hotlink their images.

The thing is, when you test it from a "notepad html page", no referer is sent. This is also for security reasons, but from your browser's side: Sending file:///C:/Users/JohnDoe/Desktop/MyPrivateFiles/page.html as referer URL would disclose private information from your computer. That's why nothing is sent. Therefore, the image is loaded - the same as if you copy and paste the URL into the address bar of your browser (then also no referer is sent).

However, when you include it on your website on the Internet, your page URL is sent as referer. The "vclogos" website now appears to check this value and return nothing if a referer is sent which is not one of their own (I'd guess they accept only http://www.vclogos.co.uk/something so it will only work if it's included in their own website, not yours).

Long story short, you just can't load this image inside your website directly from this URL.

The only way would be to use a web request on the server side in ASP.NET which fetches the actual image and then serves it to the client as a resource which, from the browser's point of view, comes from your server (who got it from "vclogos" first, but without sending a referer). The thing is that if your server fetches the image data, you have control over what headers you send. (Unlike your website which, once loaded in the browser, doesn't have this control - the browser will send your page URL as referer and there is nothing you can do about that.)

CherryDT
  • 25,571
  • 5
  • 49
  • 74
  • Yes you are right because when i use web client it works.So, it means i can not use this url in img tag :( – Tabish May 19 '16 at 10:53
0

Just a detail:

http://www.vclogos.co.uk/logo.php?subid=d18f655c3fc147&amp;imgid=11542

is a link to a blank page...

http://www.vclogos.co.uk/logo.php?subid=d18f655c3fc147&imgid=11542

is the link to an image.

You are sending an encoded URL. Always use the decoded URL (such as urlencode in php or HttpServerUtility.UrlEncode Method (String) in aspx)

Bonatti
  • 2,778
  • 5
  • 23
  • 42
  • It is also not working HttpServerUtility.UrlEncode Method (String) i did it on code behind using web client its working but i wanted to know why it is not working in img tag i don`t want to work on code behind because i have created website and adding this url to the database so i don`t want to change it on the whole website. – Tabish May 19 '16 at 12:04
  • Can you confirm in your response page (do a get on your system, and read the site as char sequence, or even use the browser "view source code"), that the tag has `&` or `&` in the tag? – Bonatti May 19 '16 at 12:08
  • Please, read the documentation on writting URL on client messages. Its been a while since I used ASP.net so I dont remeber the details [but this is likely to help](http://stackoverflow.com/a/1148326/4903925). You are sending the wrong URL to the client, thats why you wont see the image. – Bonatti May 19 '16 at 12:28
  • thanks for concentration i study the topic you said but i am not giving the wrong URL because it works on Notepad created html page . – Tabish May 19 '16 at 14:07