Asp.net下实现隐藏真实下载地址(可以实现简单的防盗链)


现在随着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管理员!");
                }

            }


当然这样也有弊端,就是用户只能用IE单线程进行下载,对于分量小的下载地址来说这个无所谓了,如果各位还有其他更好的办法,欢迎补充~~
posted @ 2007-09-27 16:41  liudao  阅读(1541)  评论(3编辑  收藏  举报
51Aspx.com 版权所有