Results 1 to 6 of 6

Thread: invalidating direct download request[Resolved]

  1. #1

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280

    Question invalidating direct download request[Resolved]

    Hi all,
    I m making an web application where user are presented various pdfs for download after taking some inputs from them. My application checks the user inputs and provides various links to the pdf files to be downloaded.

    eg:

    www.mydomin.com/files/PDF/form2E.pdf.

    If user knows the above file location he simply writes the above address and downloads this file. I want to prevent that.

    ny idea(s).

    Thnaks
    Last edited by aks_1610; Jul 12th, 2005 at 03:57 AM. Reason: Resolved
    A man with nothing to live for has everything to fight for...

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: invalidating direct download request

    Have a "download.aspx" page which takes the filename as a parameter, and does a Response.writefile to the browser. This way, you are in control.

    VB Code:
    1. Dim FilePath As String = strFileName
    2.         Dim TargetFile As New System.IO.FileInfo(FilePath)
    3.  
    4.         ' clear the current output content from the buffer
    5.         Response.Clear()
    6.         ' add the header that specifies the default filename for the Download/
    7.         ' SaveAs dialog
    8.         Response.AddHeader("Content-Disposition", "attachment; filename=" + _
    9.             TargetFile.Name)
    10.         ' add the header that specifies the file size, so that the browser
    11.         ' can show the download progress
    12.         Response.AddHeader("Content-Length", TargetFile.Length.ToString())
    13.         ' specify that the response is a stream that cannot be read by the
    14.         ' client and must be downloaded
    15.         Response.ContentType = "application/octet-stream"
    16.         ' send the file stream to the client
    17.         Response.WriteFile(TargetFile.FullName)
    18.         ' stop the execution of this page
    19.         Response.End()

  3. #3
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: invalidating direct download request

    If you are still worried that users might guess the PDF location then you could store them outside of the web root as mendhak's code could be adapted to still work with this.

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  4. #4

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280

    Re: invalidating direct download request

    Thank u very much.........
    A man with nothing to live for has everything to fight for...

  5. #5
    Addicted Member jewel's Avatar
    Join Date
    Jul 2003
    Location
    truly asia
    Posts
    153

    Re: invalidating direct download request[Resolved]

    is it possible to not show the open/save dialog box and force save the file to a temporary location in the client's pc?

    thanks
    xoxo

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: invalidating direct download request[Resolved]

    No. That's a security breach. I could create a malicious program that does the same thing and destroy the user's life!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width