With the increasing popularity of download tools such as flashget and Xunlei, some download websites can be directly captured. However, in some cases, you do not want to expose the addresses for anti-leech protection or permission restrictions, there are many methods for anti-leech protection under Asp.net. I have written one here (the new version of 51aspx will be adopted). I hope you can discuss it as follows: 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 ("This file does not exist. Please contact the 51aspx administrator!");
}
}
Of course, this also has a drawback, that is, users can only download with a single ie thread. It doesn't matter if the size is small. If you have other better methods, please add them ~~