C#下载代码,防迅雷

protected void btn_Download_Click(object sender, EventArgs e)
    {
        string strFileUploadPath = "Files/";
        //从列表框控件中读取选择的文件名
        string strFileName = lb_FileList.SelectedValue; //组合成物理路径
        string strFilePhysicalPath = Server.MapPath("~/" + strFileUploadPath + strFileName);
        Response.Clear();
        Response.ContentType = "application/octet-stream";
        Response.AddHeader("Content-Disposition", "attachment;FileName=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8));
        Response.WriteFile(strFilePhysicalPath);
        Response.End();
    }

原文地址:https://www.cnblogs.com/liufei88866/p/1767497.html