Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Our Top 10 Tips for Classic ASP : Page 2

Tidy up your server-side programming techniques with these 10 great tricks for classic ASP.


advertisement
Logging File Download

This is a very simple and elegant method to monitor how many people download a resource from your Web site. Former ASP Pro Ken Cox provides a brief solution to this often-asked question.

Question:
We need to keep track of users' file download activity on our site. When a user clicks on a hyperlink to download a file, it will run an ASP page on the server to log something into SQL Server and then download the file into the client. How can an ASP page download a file back to the client after the logging process?



Answer:
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 (Don't click on this link, it is only for demonstration, it won't do anything)

The above link was created using the following code:
<A HREF="dnladd.asp?filename=code.zip">Download code.zip</A>

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 with these lines:

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

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



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date