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>
Member
122 Points
387 Posts
Re: Hotlinking is Eating up my website's BANDWIDTH
Sep 28, 2005 03:44 AM|FancyKetsup|LINK
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>