Click here to Skip to main content
12,360,037 members (61,164 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: web-dev
Hi folks,
I want to know how I can track my downloads and hide direct links.
like: http://example.com/direct.zip
to:http://example.com/download?file=direct.zip or some like this.

How can do this?
Posted 17-Jun-12 7:55am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

providing file name in url is like giving the exact path. you can use the following way to achive it.

provide list of download - ables on a page. use user clicks on desirable file you will redirect it to download.aspx page with productid in querystring (download.aspx?pid=5)

at download page use this code under a switch case block with pid as cases.

this example deals with excel sheet and the best points are

1. There will no redirection of aspx page, but file will be downloaded.
2. User will not come to know the path of file from URL


Here's the code is :

FileInfo file = new FileInfo(PathToExcelFile);
if (file.Exists)
{
   Response.Clear();
   Response.ClearHeaders();
   Response.ClearContent();
   Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
   Response.AddHeader("Content-Type", "application/Excel");
   Response.ContentType = "application/vnd.xls";
   Response.AddHeader("Content-Length", file.Length.ToString());
   Response.WriteFile(file.FullName);
   Response.End();
}
else
{
   Response.Write("This file does not exist.");
}

Dont forget to mark as answer.
  Permalink  
Comments
SAKryukov 17-Jun-12 22:00pm
   
I recommend OP to accept this as the answer, voted 5.
--SA
Sandeep Mewara 18-Jun-12 3:16am
   
Good answer. 5!
sinhasourabh 18-Jun-12 7:10am
   
Thanks everyone ... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 17 Jun 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100