im trying to find a way to do an action when someone accesses a image file.
example would be someone views 'http://site.com/image.jpg' then say i want to log who has veiwed this file in my database.
ive heard of ad sites doing somethign like this for tracking people but i have a different plan.
i want to avoid having to log it by calling the image from a page using params like 'http://site.com/log.aspx?img=image.jpg' i dotn want to do that.

anyone have ideas how to do this?

there is a way of doing this. I use it extensively for tracking as you mentioned. You need to use an http module. Change your image url in the webpage to http://site.com/notanimage.jpg then in your http module you check for the name, do whatever logging you need and then replace the request with the original url (http://site.com/image.jpg).

If you need code let me know and i will post some (have to change some of mine not to give commercial secrets away :D) IT is only a few lines :)

there is a way of doing this. I use it extensively for tracking as you mentioned. You need to use an http module. Change your image url in the webpage to http://site.com/notanimage.jpg then in your http module you check for the name, do whatever logging you need and then replace the request with the original url (http://site.com/image.jpg).

If you need code let me know and i will post some (have to change some of mine not to give commercial secrets away :D) IT is only a few lines :)

Hi,

Can you send the code snippet to me please on <EMAIL SNIPPED>

Thanx in advance..
Rgds,
Ravin

commented: 3 years late, and then it's only a "plz send me the codez" whiner -5

Hi,
Heres a simple way to do it without HttpHandlers or mapping extensions to the aspnet_isapi.dll.

1. Add a script manager to your page or master page (tut tut if don’t have one already, this is the AJAX revolution!) Make sure you set the EnablePageMethods property to true). Also make sure the script manager is inside your form tag.
2. Create a public static method in your code behind with [WebMethod] above it and add System.Web.Webservices to your usings. Add your handling code, you could update your database, increment a counter or write to a log file.
3. Add an image to your page which has an onload=”PageMethods.TheNameOfYourPageMethod” attribute.

here's a complete tutorial with code:

http://web2asp.net/2009/01/tracking-visitors-in-aspnet-by-using.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.