Jim wrote on 26 mrt 2004 in microsoft.public.inetserver.asp.general:
After a member registers, he's able to access and download any file
available. We want to avoid the end user being able to distribute an
URL to these files thereby making it simple for other users to
download them.
Solution I'm working on:
I have a variety of files (html, pdf, doc, xls, and others) sitting
outside my "wwwroot" folder. I have an ASP script which checks the
MIME type for the given file and now, my problem is, how do I use the
FileSystemObject to grab those files and display them to the user?
Let's suppose the user is requesting demo.html. I use the FSO to open
the demo.html in the folder outside the wwwroot, and then set the mime
type and then what do I do? Response.write? What about binary files
which need to trigger a download action?
[expecting: session("loggedIn") = true]
html files sh/could be renamed to asp files, put in to the root tree and
headed as:
<% if not session("loggedIn") then server.transfer "/404.asp" %>
=================
or stay where they are and be accessed by a same-named asp file
"theFile.asp" containing:
<%
if session("loggedIn") then server.transfer path & "theFile.html"
server.transfer "/404.asp"
%>
==================
other files can be accessed by a same named asp file like
"mydoc-doc.asp"
<%
if not session("loggedIn") then server.transfer "/404.asp"
Response.Clear
strFileName= path & "mydoc.doc"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile strFilePath
Response.AddHeader "Content-Disposition", "inline;"
'' is this right ????
Response.ContentType = "application/MSWord" ' OR ....
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
%>
not tested as such.
Guru' are invited to improve on this in a follow up
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)