如何跟踪与ASP.NET下载? [英] How to track downloads with ASP.NET?
本文介绍了如何跟踪与ASP.NET下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用ASP.NET跟踪下载?
How to track downloads with ASP.NET?
我想找到多少用户完成文件下载?
I want to find how many users completed the file download?
怎么也可以从特定IP限制用户?
Also How can make restrict user from specific IP?
例如,如果用户下载 http://example.com/file.exe
,轨道会自动工作。
for example if a user download http://example.com/file.exe
, the track will work automatically.
推荐答案
如果您想从您的网站下载计,创建一个下载页面,并请求数:
If you want to count downloads from your site, create a Download page and count requests:
链接文件应该像 Download.aspx?文件= 123
protected void Page_Load(object sender, EventArgs e)
{
int id;
if (Int32.TryParse(Request.QueryString["file"], out id))
{
Count(id); // increment the counter
GetFile(id); // go to db or xml file to determine which file return to user
}
}
或 Download.aspx文件= /文件/ file1.exe
:
protected void Page_Load(object sender, EventArgs e)
{
FileInfo info = new FileInfo(Server.MapPath(Request.QueryString["file"]));
if (info.Exists)
{
Count(info.Name);
GetFile(info.FullName);
}
}
要限制到您的下载页面访问:
To restrict access to your Download page:
protected void Page_Init(object sender, EventArgs e)
{
string ip = this.Request.UserHostAddress;
if (ip != 127.0.0.1)
{
context.Response.StatusCode = 403; // forbidden
}
}
这篇关于如何跟踪与ASP.NET下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文