Visual InterDev: Logging File Download

Sometimes it is useful to keep track of users’ file download activity on your site. When a user clicks on a hyperlink to download a file, you can run an ASP page on the server to log something into SQL Server and then download the file into the client. The trick is to use a hyperlink to launch a second “background” script that logs the filename and initiates the download. If the second script doesn’t produce any HTML output, the first page stays on the user’s browser screen.

Here’s how the hyperlink looks in the first file:

 Download code.zip

When the user clicks the hyperlink, we pass the requested filename to the second file,dnladd.asp. Dnladd.asp contains the script and SQL commands that write the filename and other information to the database. After that, dnladd.asp initiates the download withthese lines:

 Response.ContentType = "application/x-zip-compressed" Response.Redirect request("filename")

Remember: don’t put any HTML code in dnladd.asp.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: