2

I have a situation where I have to make a centralized image website. I want to secure those images from direct access. I want to send response with a watermark over it depending on request parameter. What is the best approach for it.

So far I have created a content website and directly accessing image. Should I create handler from response. But if I use handler will it be slow (response).

Kindly suggest me the best approach.

Mark Ursino
  • 31,209
  • 11
  • 51
  • 83
शेखर
  • 17,412
  • 13
  • 61
  • 117

2 Answers2

1

An image handler is the way to go, you will be able to check the http header referer and only serve image when appropriate.

There is an article on the code project that has all the parts you need:

http://www.codeproject.com/Articles/126421/Image-Handling-In-ASP-NET

You'll have to ignore certain sections and expand on others, but there is basically everything you need in the article.

ilivewithian
  • 19,476
  • 19
  • 103
  • 165
  • Do you think that there will be delay if i use handler – शेखर Feb 04 '12 at 10:34
  • Yes. The single fastest way to get a file out of IIS is to let IIS serve it directly. What you could do is cache the results of your water marked image to a folder and then use Server.TransmitFile to serve it. Also the delay may be minimal and therefore completely aceptable for your application. – ilivewithian Feb 04 '12 at 10:41
  • I am having around 400,0000 images so far and it will grow as the time passes by. And likely to be at least 10 different version of each Images. Will it be a good idea to cache the images? – शेखर Feb 04 '12 at 10:59
  • No idea, it depends on your constraints. 4,000,000 images isn't much if you have resources for 100,000,000. You'll need to do some bench marking, but I'd suggest that if you try to serve large numbers of images that need watermarks, without some form of cache, you'll run into problems. – ilivewithian Feb 04 '12 at 16:09
0

This might help you: http://www.naveenbhat.in/2012/06/directory-security-on-webservice-with.html

Here, I created the handler for html and pdf types. You can implement the logic in same way for image.

NaveenBhat
  • 3,248
  • 4
  • 35
  • 48