How to prevent image hotlink from your asp net site

Preventing Hotlinking in ASP.NET

Image hotlinking refers to the practice of displaying an image on a website by directly linking to the image file hosted on another website. This can lead to increased bandwidth usage and potential copyright infringement. In this article, we will explore how to prevent image hotlinking in an ASP.NET site.

Method 1: Referrer

One way to prevent image hotlinking is by checking the referrer of the request. The referrer is the URL of the page that linked to the image. By verifying that the referrer belongs to your own website, you can allow the image to be . Otherwise, you can redirect the request to a placeholder image or display an error message.

Method 2: Module

Another approach is to use the URL Rewrite module in IIS to block direct access to image files. This module allows you to for rewriting or redirecting URLs. By creating a rule that matches image file extensions and denying access to them, you can prevent hotlinking.

To configure the URL Rewrite module, follow these steps:

  1. Install the URL Rewrite module if it is not already installed.
  2. Open IIS Manager and select your website.
  3. Double-click on the “URL Rewrite” icon.
  4. Click on “Add Rule(s)” in the right-hand pane.
  5. Select “Blank Rule” and click “OK”.
  6. Enter a name for the rule and set the pattern to match image file extensions (e.g., .jpg, .png).
  7. Under “Action”, select “Abort Request” to deny access to the image files.
  8. Click “Apply” to save the rule.

Method 3: Watermarking

Another way to discourage image hotlinking is by adding a watermark to your images. By overlaying a visible watermark on your images, you can deter others from using them without permission. There are and available for adding watermarks to images in ASP.NET.

protected void Page_Load(object sender, EventArgs e)
    string imageUrl = "path/to/your/image.jpg";
    string watermarkText = "Copyright";
    // Add watermark to image using a library or tool
    // Display the watermarked image


Preventing image hotlinking is an important aspect of protecting your website's content and resources. By implementing one or more of the methods discussed in this article, you can effectively deter hotlinking and ensure that your images are used only within the of your own website.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents