现在随着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-Dispositionattachment; 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原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/liudao/archive/2007/09/27/908219.html