devxlogo

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.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Seven Service Boundary Mistakes That Create Technical Debt

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.