3
Answers

Prevent users from downloading a file using "direct targeting" URLs?

Satyapriya Nayak

Satyapriya Nayak

14y
4.3k
1

Hi!
Well I have always wondered how this is done...how do you actually prevent a user from beeing able to download a file by directly targeting the URL to the file in the adressbar?
Lets for instance say we have the file "File.zip" and its placed in the root directory for a domain called myfiles.com...if we just put the "File.zip"-file directly in the very root, then we would be able to type www.myfiles.com/File.zip and then we would be able to download the file...but how do I prevent that?..is there a way?..cause maybe I just want special users to be able to download that file..
To put it in a more realistic case....lets say we actually have created the above site, but in this case you can actually buy the file "File.zip"...then you only want customers to be able to download it who are register users and preventing people from simply typeing the URL..

Any ideas about how to prevent this?

Thanks in advance!
 
Answers (3)
1
Amit Gupta

Amit Gupta

NA 16.5k 25.6k 8y
If the database column is type of string then it recommend you to change the datatype to decimal, it will help you in future and many more queries.
 
However, if currency contains ,(comma) and you need to validate that by using the replace method
 
String cur ="12,000";
var value = Convert.ToDecimal (curr.Replace (",", "");
 
// now value contains only numbers without and seperator