Asp.net下實現隱藏真實下載地址(可以實現簡單的防盜鏈)

來源:互聯網
上載者:User
現在隨著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單線程進行下載,對於分量小的來說這個無所謂了,如果各位還有其他更好的辦法,歡迎補充~~

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.