Anti-theft chain method

xiaoxiao2021-03-06  115

Preventing the chain download problem often contains something on the network, sometimes it is directly to copy a similar http://193.100.100.56/testwebsolution/webapplication1/testwebsolution/webapplication1/testwebsolution/webapplication1/test.rar address is ready to download the Test.rar file, but is notified without login or Directly jump to other pages, then download the file directly after logging in. To achieve the above situation, it is easier in the .NET world. 1. First create a class library project ClassLibrary1, implement it as follows: use system; use system.Web; // Reference System.Web Component Namespace ClassLibrary1 {public class myHandler: httphandler {public myhandler () {} #region IHttpHandler members public void ProcessRequest (HttpContext context) {// jump to WebForm1.aspx, the output rar WebForm1.aspx file HttpResponse response = context.Response; response.Redirect ( "http://193.100.100.56/TestWebSolution/WebApplication1/ Webform1.aspx ");} public bool isreusable {get {// Todo: Add myHandler.Isreusable getter implementation return true;}}}} #endregion}} 2, create the Web project WebApplication1 for testing.

Add the following nodes in the configuration file web.config file node: httphandlers> 3, in Webform1.aspx Add a text to "download" button, its Click event is as follows: fileinfo file = new system.io.fileinfo (@ "g: /webcenter/testwebsolution/webapplication1/test.rar"); // fileInfo Class in system.io namespace response.clear (); response.addhead ("content-disposition", "filename =" file.name); response.addheader ("Content-length", file.length.teostring ( )); String fileExtension = file.extension; // According to the MIME type Switch (FileExtension) {CASE ".MP3": response.contentType = "Audio / MPEG3": response.contentType = "AUDIO / MPEG3": Response. ContentTyPe = "VIDEO / MPEG"; Break; Case "JPG": response.contentType = "image / JPEG "; BREAK; CASE" ........ ": response.contenttype =" .... "; break; default: response.contenttype =" Application / OcTet-stream "; Break;} Response .Writefile (file.fullname); response.end (); 4, the last step is to add an application extension in IIS. In the "default website" -> "Properties" -> "Proterly" -> Configuration.

转载请注明原文地址:https://www.9cbs.com/read-99989.html

New Post(0)