Last post Jun 11, 2009 08:32 AM by xmen
Jun 11, 2009 08:05 AM|xmen|LINK
I want to restrict my static images from direct url, like www.abc.com/abc.jpg. So to do that, I added a class, inherit IHttpModule and add some lines in web.config. But that class never called.
here is class code
public class XImageHandler : IHttpHandler
public void ProcessRequest(HttpContext context)
if (context.Request.UrlReferrer == null ||
context.Request.UrlReferrer.Host.Length == 0 ||
context.Request.Url.Host.ToString()) == 0)
public bool IsReusable
<add verb="*" path="*.jpg"
<add verb="*" path="*.png"
any idea ?
Jun 11, 2009 08:26 AM|eric2820|LINK
The first thing to do, is use the correct tool for the job. And the correct tool for you is an HttpModule not an HttpHandler. Read on for why...
An HttpModule has the opportunity to inspect every request that comes in, while
an HttpHandler is designed to handle a custom file type.
In your handler, if you only want to handle jpg files, then you'd use something like this:
Jun 11, 2009 08:32 AM|xmen|LINK
Yes I tried that just before HttpHandler but the problem is that its called only when any page loads. Not when an image loads.
PS. I tried HttpModule when I was developing site and it was working, but after that I just commented its 'add' tag in web.config. And when I uncomment it, its not working on image load.
I changed the class name as well as HttpModule name, now ITS WORKING....