现在随着FlashGet和xunlei等下载工具的日益普及,下载网站的一些下载地址都能直接被捕获到,,但是有些时候为了防盗链或权限限制不想对地址进行暴露,对于Asp.net下的防盗链有很多方法,我这里写了一种(51aspx的新版本将会采纳)希望大家讨论一下:
string
filename
=
"
51aspx_Test.rar
"
;
if (filename != "" )
{
string path = Server.MapPath(filename);
System.IO.FileInfo file = new System.IO.FileInfo(path);
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
else
{
Response.Write("该文件不存在,请联系51aspx管理员!");
}
}
if (filename != "" )
{
string path = Server.MapPath(filename);
System.IO.FileInfo file = new System.IO.FileInfo(path);
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
else
{
Response.Write("该文件不存在,请联系51aspx管理员!");
}
}
当然这样也有弊端,就是用户只能用IE单线程进行下载,对于分量小的下载地址来说这个无所谓了,如果各位还有其他更好的办法,欢迎补充~~
本文转自 liudao 博客园博客,原文链接:http://www.cnblogs.com/liudao/archive/2007/09/27/908219.html,如需转载请自行联系原作者