How can I hide/secure image path in asp.net? I don’t want the user see image path directly.
I have googled with my problem and found the following URL:
http://www.codeproject.com/KB/web-security/ImageObfuscation.aspx
On this page it suggests changing the image path like this:
<img ID='ImageControl'
src='ShowImage.axd?Path=<% EncryptString("C:\Images\img.ext", Page) %>'
But if user copy this image src and paste it into their browser with the domain name then it will show image.
It really depends on what you are trying to achieve.
If you’re trying to stop people linking to your images from another site, then the best option would be to extend the handler you mentioned in your question to only return an image if the
Request.Referreris your own site.This means that if they did then try and link to the image via your handler, they’d only see a broken image/no image, they wouldn’t be able to request the image directly in their browsers, etc.
You should also probably include some sort of time stamp in the encrypted path, and reject requests that come from too long ago – this will again limit the validity of the links:
Then in your handler:
If you’re trying to stop people downloading your images then you’re not really going to stop more than the most basic internet user – after all to display the image on your site, you’ll need to send a copy of it to the client browser.
However, a couple of possible options to make it harder:
Response.Cache.SetCacheability(HttpCacheability.NoCache);Response.Cache.SetExpires(DateTime.Now);At the end of the day, if you put some content online, then it’s very hard to stop the most dedicated “thief” from taking it and using it.