views:

46

answers:

1

This is really a couple of questions about preventing unauthorized attempts to access a specific file type. Here go the questions:

  1. How do I prevent users from directly requesting a type of file? Do I write an HTTP handler?
  2. After preventing a direct download, can my app still explicitly serve that file type? How?
+3  A: 

The way to do this is to:

  1. Put all your tif files in a non publicly accessible location
  2. Create an IHttpHandler to serve these tif files based on authentication (or whatever limitation you choose).
  3. (Optional) Set up a rewrite rule so that all tif requests go through your IHttpHandler. This creates nice URL's again.
Paul Mason
Note that there is no bullet-proof way to prevent people from requesting a file while allowing your app on their machine to request it.
SLaks
There is... you're web app could be in c:\inetpub\wwwroot, whereas your tif files could be in c:\webdata\. Then it is just a matter of setting appropriate application pool permissions. At least, I thought you could do it that way? Of course I could be misinterpreting the initial question :)
Paul Mason
I think SLaks means that if you hard-code a key in your client app, users will find it.
Matthew Flaschen
but... when the browser renders the image, it can still be copied and taken from the browser. once it's rendered (even through an iHttpHandler), it is considered a physical fine (even if it's not).
rockinthesixstring
Hmmm; all valid points. I interpreted the question that they were simply wanting to prevent unauthorised requests to a file type (i.e. they must have passed authentication or something). Could be wrong of course.
Paul Mason
@Paul Mason - You are correct. Just prevent unauthorized attempts to access a specific file type.
flipdoubt