How to implement anti-leech protection in ASP. NET

Source: Internet
Author: User

Website leeching is very immoral. We can't just condemn the unqualified guys, and we have to technically prevent the theft of website resources.

To implement anti-leech protection, we have to block a knife when IIS processes resources similar to image files and check whether its pass is legal. We have to resolutely drop illegal requests.

Let's take a look at a picture of IIS processing requests.

This picture shows the process of processing an ASP. NET pipeline. When IIS discovers the request ASP page, it is handed over to ASP. DLL for processing. If An ASPX page is requested, it is handed over to aspnet_isapi (IIS extension) for processing. If it is an HTML page, text file, JPEG, or GIF image, then the IIS process will handle it by itself.

We can see that an httpmodule and httphandler are required in the ASP. NET processing pipeline. Httphandler is used. That is to say, we need to implement an httphandler to process images, compressed packages, and other requests.
It is not difficult to implement it. You only need to inherit and implement the ihttphandler interface.

Isreusable indicates whether the request can be cached and how the processrequest method processes the request.Code.

1. We can determine whether the request is legal by judging context. Request. urlreferrer, and then output the file through context. response. writefile (context. Request. physicalpath.
2. Configure the config file to let Asp.net know that httphandler is available. The format is similar to the following.

• Verb can be "get" or "Post", indicating that the get or POST request is processed. "*" Indicates that all requests are processed. Here, get requests are processed.
• PATH indicates processing the corresponding file. "*. aspx" indicates processing the requests sent to all aspx pages.
• In the type attribute, the string before the comma specifies the Class Name of the httphandler implementation class, and the subsequent string specifies the name of the DLL file.
3. Finally, configure iisat the end to map the files to be processed to aspnet_isapi.exe.

In this wayGIFThe image request will pass through ourHttphandlerSo that we can cut off the leeching "black hands ".

But how do you prevent leeching?GIF,JPG,RAR,Zip,Txt,BMP, Etc.,We wantWeb. config? IfHandlerChanges to be modifiedWeb. config. Is there a good solution? You can think about it and look for it. Next time, I will continue to talk about :)

Reference resources:
Ugoer
Msdn

I originally wanted to write where it came from, but which image is preventing theft (Khan ....) I don't want to write it anymore. By the way, PS Dudu can only upload a large number of images in the past. Now the limit is 200 kb. I really don't know why?
Related Article

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.