If you would like to (for example) make sure all the jpegs on your site are displayed including a copyright text or something like that, you could use the example I posted before. But it would be easier to write a custom httpHandler. Here’s a small howto:
1. Add a class to a WebApplication, and give it a decent name. Mine is customHandler.
2. Have the class implement the IHttpHandler interface (found in the System.Web namespace)
3. Implement the right methods
4. Use ‘ProcessRequest‘ to process the request the way you want to
5. Register the handler in the web.config
6. ‘Register’ the handler in IIS
7. You’re good to go!
Now for some exampe-code. Steps 1 to 4 can be found here:
public class customHandler : IHttpHandler
public void ProcessRequest(HttpContext context)
plaatje = context.Request.PhysicalPath;
image = Image.FromFile(plaatje);
graphics = Graphics.FromImage(image);
//TODO: add dynamic calculation of the drawstring location
graphics.DrawString("bloggingabout.net", new Font("Verdana", 14, FontStyle.Bold), new SolidBrush(Color.White), 10, 280);
context.Response.ContentType = "image/jpeg";
public bool IsReusable
Step 5 looks a little bit like this:
<add verb="*" path="*.jpg" type="handlerTest.customHandler, handlerTest"/>
Step 6 is a little bit tricky. You will have to open the Internet Information Services manager and open the properties for the the website you want the handler to work for. Om the first tab page, open up configuration. Now, first select a file extension which is served by ASP.Net, like .asax or .aspx and click edit. Copy the file that’s used over there (it should be C:WINDOWSMicrosoft.NETFrameworkv1.1.4322aspnet_isapi.dll). Close the dialog and click to add a new one. Here, put the copied value in the right textbox and fill in .jpg as the extension you want to be handled. Next close all open boxes by clicking OK and you should be ready to go.
The image it produced with my code: