Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Web-Development
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 8: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 at 17-Jun-12 22:00pm
   
I recommend OP to accept this as the answer, voted 5.
--SA
Sandeep Mewara at 18-Jun-12 3:16am
   
Good answer. 5!
sinhasourabh at 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
0 OriginalGriff 440
1 Sergey Alexandrovich Kryukov 424
2 CPallini 210
3 King Fisher 209
4 CHill60 180
0 Sascha Lefévre 75
1 OriginalGriff 70
2 F-ES Sitecore 55
3 Peter Leow 50
4 Dave Kreskowiak 40


Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 17 Jun 2012
Copyright © CodeProject, 1999-2015
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