Click here to Skip to main content
16,022,752 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: (untagged)
Hi All,
I've a image gallery website where members can upload and restrict the access to few friends. The problem is, images are directly accessible from browser. How could I restrict specific folder to accessible from aspx pages only.

Regards,
Neeraj
Posted

Answer 2 is good, but what happen if we deploy it to real server...Can we still enable to reconfig the IIS at real host....
The third answer is using ASHX handler.
Check the link below
http://aspalliance.com/1322_Displaying_Images_in_ASPNET_Using_HttpHandlers.all#top
 
Share this answer
 
There are two ways of doing this - an easy "hack" and a "proper" way...

The easy way is simply to save your images with randomly assigned (GUID-type thing) filenames which can't be guessed. This doesn't stop people linking directly to your images once they know the filename of course, but unless your images are highly popular that is unlikely to be a problem, but it will stop them from finding images until you reveal the address.

The proper way is to write a custom handler; you can find an example here[^]. Note though that depending on your version of IIS you may need to perform some steps differently - that article assumes IIS6; once you get above this you need to write your config file differntly, for one thing...
 
Share this answer
 
Neeraj Arora wrote:
How could I restrict specific folder to accessible from aspx pages only


Write a http handler which handles requests for images. Check the authentication and display necessary messages. Make sure you map the extensions to ASP.NET in IIS settings.

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900