. 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
- Public class cehandler: ihttphandler
- {
- # Region ihttphandler
Employee
- 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
- }
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
- <Httphandlers>
- <Add verb = "*" Path = "*. rar" type = "mychy. Soft. cehandler, mychy. Soft"/>
- <Add verb = "*" Path = "*. Zip" type = "mychy. Soft. cehandler, mychy. Soft"/>
- </Httphandlers>
IIS settings
Click Configuration
Click Add
Executable File: C: \ WINDOWS \ microsoft.net \ framework \ v2.0.50727 \ aspnet_isapi.dll