locked
Hotlinking is Eating up my website's BANDWIDTH RRS feed

  • Question

  • User28423845 posted
    hello pleaseeee help me,

    I've a website with a lots of wallpapers and images, and i'm sure many people are HOTLINKING and pointing to my images from their websites, which is EATING UP my website's Bandwidth, please tell me the ways, or scripts or any BEST ways to stop people from using my Bandwidth....

    I've seen that www.tripod.com dosen't allow people to HotLinks images on it's webserver and displays a message like, "This image is hosted on tripod.com etc etc..."

    please help !

    thanks...

    regards,

    Gurjit Singh
    Tuesday, September 20, 2005 2:19 AM

All replies

  • User1220620067 posted

    <compile this into a dll and put into your /bin>
    using System.Web;

    public class GifHandler : IHttpHandler
    {
     public void ProcessRequest(HttpContext context)
     {
      if(context.Request.UrlReferrer.Authority.ToString() == "mydomain.com")
      {   
       context.Response.WriteFile(context.Request.RawUrl.ToString());
      }
      else
       context.Response.WriteFile("StopStealingMyImages.gif");
     }
     public bool IsReusable
     {
      // To enable pooling, return true here.
      // This keeps the handler in memory.
      get { return false; } 
     }
    }
    </complie>

    <add this to you web.config>
    <httpHandlers>
               <add verb="*" path="*.gif" type="GifHandler,HandlerDLL_Name" />
    </httpHandlers>
    </web.config>

    Need to map .gif files in IIS to the asp_isapi.dll

    You don't have to serve them back anything you can just do context.Response.Write("") and they will get a broken image on their site. But my GAWD it would be fun to make a real nasty gif with a up yours message on it, or informing their visitors they are stealing images from your site [:D]. Be aware I haven't done much testing with this and one heads up, right off top of my head, would be your image paths within your own site will have to be root relative for this to work. Otherwise you will have to get into some heavy string manipulation. Possible I guess to do all images with absolute urls and string handling won't be too bad. But if you are using different ways throughout your site then the string handling is going to be a pretty big hit on performance if you are serving lots of images.

    Monday, September 26, 2005 4:16 PM
  • User1220620067 posted

    The previous example I posted will not work untill your able to get a version of Asp.Net that UrlReferrer works properly. Below is another solution using cookies. Its not production quality code but does show general concepts. Need to be careful with it though or you could be serving up messages/images that display as if your are stealing your own images(not good). What makes this work is always expiring any page requested from your site so it always refreshes(can be good/bad depending on your needs). With some effort and thought it may be possible to develope it further and resolve this to fit your needs. It also needs further development of the string handling to be sure it is finding all the images that are being request from your site(ie subfolders within image folder). Furthermore anyone stealing images can still steal them as long as they visit your site first and get a cookie written from your site(current implementation could be improved). But once they close their browser once again they are recieving stolen image messages untill they revist your site and get another cookie set. A good understanding of cookies is required to make this work properly or even develope it further. In conclusion this is a workable and viable concept it some cases .

    <handler>
    using System;
    using System.Web;
    public class GifHandler : IHttpHandler
    {
    public void ProcessRequest(HttpContext context)
    {
    if(context.Request.Cookies["SiteName"] != null && context.Request.Cookies["SiteName"].Value== "domainname.com")
    {
    int len = context.Request.Url.Segments.Length-1;
    context.Response.WriteFile(context.Request.Url.Segments[len].ToString());
    }
    else
    {
    context.Response.WriteFile(context.Server.MapPath("StopStealingMyImages.gif"));
    }
    }
    public bool IsReusable
    {
    // To enable pooling, return true here.
    // This keeps the handler in memory.
    get { return false; }
    }
    }
    </handler>


    <aspx code behind>
    private void Page_Load(object sender, System.EventArgs e)
    {
    HttpCookie cookie =
    new HttpCookie("SiteName","domainname.com");
    Response.Cookies.Add(cookie);
    }
    </aspx code behind>

    Wednesday, September 28, 2005 3:44 AM
  • User1220620067 posted
    The previous example I posted will not work untill your able to get a version of Asp.Net that UrlReferrer works properly

    I stated this above and I am wrong. It isn't a problem with the UrlReferrer  property in asp.net it was my firewall. With that knowledge using UrlReferrer is useless in any form that I can envision, because you can't know if the client is using a firewall that is blocking/stripping this header information. [:'(]
    Thursday, September 29, 2005 7:47 AM