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?