跟踪下载文件 [英] track downloading files

查看:66
本文介绍了跟踪下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我想知道如何跟踪我的下载并隐藏直接链接.
像:http://example.com/direct.zip
到:http://example.com/download?file = direct.zip或类似的文件.

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?

推荐答案

在url中提供文件名就像给出确切路径一样.您可以使用以下方式实现它.

在页面上提供下载列表-能.使用用户单击所需文件时,您会将其重定向到带有查询字符串中的productid的download.aspx页(download.aspx?pid = 5)

在下载页面上,将此代码在pid为case的switch case块下使用.

这个例子处理的是excel表格,最好的地方是

1.将不会重定向aspx页面,但是将下载文件.
2.用户不会从URL知道文件的路径


代码是:

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.


这篇关于跟踪下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆