I have a following setup. I have a web application and in the .css of this application I define a background image to be presented when I hover over some element.
I want a script or something of that sort that sits on the server and when the image is accessed, it calls an action on the application. Unfortunately, I have no idea where to begin.
I want to know if and some hints on how to write a server side component that executes an action in web application based on the request for a file by css.
I am on Windows7, ASP.NET MVC.
EDIT
So, I have followed your suggestions on using httpHandlers. It seems like the perfect solution. However, I am running into problems.
I have followed this very helpful link http://www.phpvs.net/2009/08/06/aspnet-mvc-how-to-route-to-images-or-other-file-types/ but I was just unable to get a hit on a route
routes.Add("ImageRouting", new Route("Content/themes/base/images/{filename}.png", new ImageRouteHandler()));
My only other route is the one generated by default by MVC template.
So I figured out that the requests to a file are not handled by default by MVC. So I had to fix that by by setting the RouteExistingFiles property of the RouteCollection to true.
Now I get proper hits on my images but for some reason, Site.css located in Content folder is not used to style the resulting html.
Any suggestions?
Add an HttpHandler in your machine.config or web.config like so:
Your verb can be “*” or “GET”, set path equal to the location of your image file on the server, and fill the type variables according to your namespace, class and handler function.
For a more detailed explanation, see:
http://www.15seconds.com/issue/020417.htm