. Net prevents leeching and thunder

Source: Internet
Author: User
. Net prevents leeching and thunder
  • Category:
    C #

  • Comment: 0
  • View: 920

. Net prevents leeching and thunder

This program needs to have its own server or be able to operate IIS's ISAPI extension

The method I use is to access context. Request. urlreferrer. Host; that is, what is the last link to access this website?

Whether the website host can be downloaded. If yes, if not, the website host can be downloaded!

New cehandler class inherits the ihttphandler interface implementation Interface Method

CSHARP code
  1. Public class cehandler: ihttphandler
  2. {
  3. # Region ihttphandler
    Employee
  4. Public bool isreusable
  5. {
  6. Get {return true ;}
  7. }
  8. Public void processrequest (httpcontext context)
  9. {
  10. String my = string. empty;
  11. My = "jeanwen.com ";
  12. String host = string. empty;
  13. Try
  14. {
  15. Host = context. Request. urlreferrer. Host;
  16. }
  17. Catch (exception E)
  18. {
  19. Context. response. End ();
  20. }
  21. Int XT = host. indexof (my );
  22. If (XT> = 0)
  23. {
  24. String url = context. Request. url. tostring ();
  25. Context. response. Clear ();
  26. Url = URL. Replace ("http ://","");
  27. Int x = URL. indexof ("/");
  28. If (x> 0)
  29. {
  30. Url = URL. substring (x + 1 );
  31. String filepath = context. server. mappath ("~ /") + URL;
  32. Fileinfo file = new system. Io. fileinfo (filepath );
  33. Context. response. addheader ("content-disposition", "filename =" + file. Name );
  34. Context. response. addheader ("Content-Length", file. length. tostring ());
  35. Context. response. contenttype = "application/octet-stream ";
  36. Context. response. writefile (file. fullname );
  37. }
  38. Context. response. End ();
  39. }
  40. Else
  41. {
  42. Context. response. End ();
  43. }
  44. }
  45. # Endregion
  46. }
Public class cehandler: ihttphandler {# region ihttphandler member public bool isreusable {get {return true ;}} public void processrequest (httpcontext context) {string my = string. empty; my = "jeanwen.com"; string host = string. empty; try {Host = context. request. urlreferrer. host;} catch (exception e) {context. response. end ();} int XT = host. indexof (my); If (XT> = 0) {string url = context. request. URL. tostring (); context. response. clear (); url = URL. replace ("http: //", ""); int x = URL. indexof ("/"); If (x> 0) {url = URL. substring (x + 1); string filepath = context. server. mappath ("~ /") + URL; fileinfo file = new system. io. fileinfo (filepath); context. response. addheader ("content-disposition", "filename =" + file. name); context. response. addheader ("Content-Length", file. length. tostring (); context. response. contenttype = "application/octet-stream"; context. response. writefile (file. fullname);} context. response. end ();} else {context. response. end () ;}# endregion}

Add webconfig. config

XML Code
  1. <Httphandlers>
  2. <Add verb = "*" Path = "*. rar" type = "mychy. Soft. cehandler, mychy. Soft"/>
  3. <Add verb = "*" Path = "*. Zip" type = "mychy. Soft. cehandler, mychy. Soft"/>
  4. </Httphandlers>
  

IIS settings

Click Configuration

Click Add

Executable File: C: \ WINDOWS \ microsoft.net \ framework \ v2.0.50727 \ aspnet_isapi.dll


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.