Forum Moderators: open
Example - authenticate your user, take them to a page listing your documents using the filesystemobject. When they select one, use fso again to copy the document from its home directory to a "temp" download directory, renaming it to the userid of the logged in user, and then response.redirect to it.
That way, each logged in user might have one stale file in that temp directory, but it prevents buildup over time and allows you to give access to it only through asp authentication.
Just one suggestion - feel free to shoot holes in it :-)
I put the code for the password check and redirect in a separate text file so I could include it on all pages that I wanted to protect.
1- Leave your PDFs in the folder where you want them
2- Create an ASP page, called something like RetrieveDocument.asp and append the file name only as your querystring parameter, so they have something like this: RetrieveDocument.asp?strFileName=MyFile.pdf to call.
3- In the ASP page you just created, first verify login credentials. If login verification fails, kick them out.
4- If login verification passes, then user a Server.Transfer to deliver the proper path of the PDF, using the querystring value. The user will never see the path directly to the PDF, and if they save the path to the ASP page, it won't work unless they are already logged in.
Note: your server.transfer command might look something like this:
Server.Transfer "/documents/" & Request.Querystring("strFileName")
HTH
-Moz
An alternative with classic ASP is to use a ADO stream:
<%
Response.ContentType = "application/pdf"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile *filepath* 'outside web root
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
%>
However, firefox chokes on the file. Adding the following below the Response.ContentType seems to fix it.
Response.AddHeader "Content-Disposition", "attachment; filename=""my.pdf"""
I'd do some thorough testing before going live... :)
in place of server transfer, put a simple frameset with your passed filename as the frame source. Something like this:
<frameset border=0 framespacing=0 frameborder=0 rows="*">
<frame src="/documentPathName/<%=Request.Querystring("filename")%>">
</frameset>
This way, the user can't see the path to the document, and you don't have to worry about the server parsing teh PDF file.
-Moz