Reputation: 1363
I am developing application for Online Book Purchases
I am giving download PDF Format book after paid money so i want secure my PDF from direct download.
Question:
1) How could I hide folder URL at the time of download PDF
2) Any security code which not allow user directly access folder or PDF
3) When click on download it will directly download PDF instead of open in browser then download
Upvotes: 1
Views: 1856
Reputation: 76547
There are a million ways to solve this problem, so I'll just shoot from the hip and throw out a few ideas that might help you.
Firstly, you aren't going to want to explicitly expose any files or folders within your application. Let your application serve them for you, if you even want to serve them at all directly. There are quite a few things that you could consider:
A potential workflow might go something like this:
If you do choose to have a link for the user to download the file explicitly, make sure you don't expose the file itself but provide an endpoint that handles determining access and ultimately serving the file like this:
// You could consider writing a custom attribute that would store which files a given
// user had access to (via claims, etc.) but make sure the endpoint requires authentication
[Authorize]
public FileResult DownloadFile(Guid fileId)
{
// Here you could explicitly check in your database to ensure the user had access
// to the requested file, otherwise revoke the request
if (CanAccessFile(context.UserId, fileId))
{
// If they can access the file, then serve it from the appropriate location
return File(...);
}
}
Likewise, you could also support scenarios where simply having access to the link would allow the user to download the file by passing in the file being requested along with a token:
// You wouldn't necessarily need authentication here because the token and
// requested file should be enough
public FileResult DownloadFileWithToken(Guid downloadToken, Guid fileId)
{
// Here you would just check your database to ensure that the token was
// valid for the specific file and if so, allow the user to download it
}
1) How could I hide folder URL at the time of download PDF?
Don't expose the file directly such that a user could access it.
2) Any security code which not allow user directly access folder or PDF?
Again - don't allow direct access to any folders or files. If you are serving these files after a payment is made, then there's no reason for your to explicitly expose them on the site/application.
3) When click on download it will directly download PDF instead of open in browser then download?
You can accomplish this behavior (regardless of how you elect to handle this process) via an HTML download
attribute:
<a href="path" download>Download</a>
Upvotes: 3
Reputation: 1
_ Your project
|_ wwwroot
|_ PDF_folder
|__ file_01.pdf
|__ file_02.pdf
By using this way, user cannot access to the file via URL.
example.com/pdf_folder/file_01.pdf
, this path will response 404 status code.
Because there is no directly link that user can access, you don't need any security code in this action.
You can try to return a File when user makes a new request:
public ActionResult Download()
{
// code goes here...
return File(...);
}
Upvotes: 1