Russell, sounds like you're trying to construct a simple, secure document
management system.
I don't have a particularly satisfying solution for the
delete-when-user-leaves approach. It's difficult to detect a users
departure accurately, which hampers this approach greatly.
If you want to pursue that, the best solution I can recommend is to have a
"heartbeat" between the client and the server. Each tick of the heartbeat
would update a "last seen" timestamp on a database table that identifies the
document. On a request for the document (which, I'm guessing, is a special
copy intended for that one user only), you compare DateTime.Now to the
timestamp the heartbeat was last seen. If it's too long, you just deny the
request and delete the document.
The heartbeat is simple enough to construct; have a hidden frame or a 1x1
IFRAME in your document display page, and the page loaded in the IFRAME can
use the auto-refresh tag at a 30 second interval. Crude, but amazingly it
works, and if the user closes their browser you can safely do cleanup in as
little as 65 seconds or so (I use 2 beats for safety).
This approach also avoids having a back-end process, but suffers from a
trash problem. If a user views their document, and dutifully closes their
browser and never requests it again, there is no further event specific to
that document. You never get to take out the trash. A back-end process
that runs every 5 mins, checks the db table for old files and deletes them
is easy to construct if you want to keep your "document cache" clean.
If I've interpreted your objectives correctly so far, let me suggest a
completely different solution;
Eliminate the cache. Store the documents somewhere else, e.g. on your
network or in the database. When a user requests a document, have them
request it from an .aspx page that goes and retrieves the document and
writes it back to the user.
This approach is much cleaner, and ultimately simpler. No temp documents,
no files to copy or delete.
/// M
"Russell" <la******@comcast.net> wrote in message
news:uN**************@TK2MSFTNGP10.phx.gbl...
Hi all,
I have a web page(a) that has a link to another web page(b). Now, on the
page load event of web page(b), I am doing the following:
Response.redirect("./test.pdf")
This pdf, if the user copies the url, can go back to it after they have
logged out of my web site.
I need to delete this file. I need to find a way to detect the web page is
closing so I can delete the pdf file.
Of course, redirecting to the pdf opens the pdf in its own page, so I
can't code to delete the file that way.
How can I detect that the user has close the pdf file?
Any help is greatly appreciated, as I need to resolve this ASAP.
Thanks
Russell