Development log: Anti-leech application based on the ihttphandler interface function

Source: Internet
Author: User

Create the urlhandler. CS file,CodeAs follows:

 

Using System. Web;

Namespace Baselibrary {
Public   Class Urlhandler: ihttphandler {
// Indicates whether the httphandler implementation class needs to be cached.
Public   Bool Isreusable {
Get { Return   True ;}
}

PublicUrlhandler (){
}

Public   Void Processrequest (httpcontext context ){
String Filename = Context. server. mappath (context. Request. filepath );
If (Context. Request. urlreferrer ! =   Null ){
If (Context. Request. urlreferrer. Host =   Null ){
Context. response. contenttype =   " Image/JPEG " ;
Context. response. writefile ( " ~ /No.jpg " ); // Replaced Image
} Else {
If (Context. Request. urlreferrer. Host. indexof ( " Vote.yeshj.com " ) >   - 1 ) // Here is your domain name, such as www.maticsoft.com
{
Context. response. contenttype =   " Image/JPEG " ;
Context. response. writefile (filename );
} Else {
Context. response. contenttype =   " Image/JPEG " ;
Context. response. writefile ( " ~ /No.jpg " );
}
}
} Else {
Context. response. contenttype =   " Image/JPEG " ;
Context. response. writefile (filename );
}
}
}
}

 

Add the following code to the

 

< Httphandlers >
< Add Verb = "*" Path = "*. Jpg" Type = "Baselibrary. urlhandler, baselibrary" />
</ Httphandlers >

 

Configure IIS for the website
In the site's main directory =, configure =, and ISAPI
An extension name is 2.16.jpg ";
Extension of the executable file address: "C: \ WINDOWS \ Microsoft. NET \ framework \ v2.0.50727 \ aspnet_isapi.dll"

In this example, when the external display chain is connected to this week's image, No. jpg will be displayed.

 

Thoughts:

In this case, I only used the .jpg anti-leech feature. How do I implement anti-leech protection in multiple image formats?

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.