Events in the file and image handlers

Apr 3, 2007

In BlogEngine.NET, all files and images that are inserted on a post will be served using an HttpHandler. Actually, they are served by FileHandler and ImageHandler respectively. They are almost identically and they both share the same event model. For the purpose of this example, I’ll stick with the file handler but the examples will work for both.

Events

There are three events on the file handler.

  • BeforeServing
  • FileServing
  • BadRequest

BeforeServing
This event is fired before a file is served, no matter if it exists on disk or not.

FileServing
This event is fired when the file exists on disk and the handler is serving it to the requesting client.

BadRequest
This event is fired when the requested file does not exist on disk and therefore cannot be served.

Uses

The events are not used anywhere by BlogEngine.NET. They are there for plug-ins to take advantage of. It would be quite easy to build an HttpModule that listens to the FileServing event and logs the request for statistical purposes. Another module could listen to BeforeServing, so it could stop the request if it comes from another website. That way you can prevent deep links to your files. The BadRequest event can be used to log non-existing files so you can fix broken links.

This is just some of the possibilities that the FileHandler's events can be used for.

The difference between the ImageHandler and FileHandler has something to do with client-side caching and content-types. Other than that they are alike.

* Only $4.95/month ASP.NET & Windows 2008 + IIS 7 Hosting! FREE SQL Included

Comments (4) -

harsha
harsha
4/4/2007 3:09:28 PM #

Mads,
  How do I change the post create date? No mater what I change to it default to current date after I save the post.

Mads Kristensen
Mads Kristensen
4/4/2007 8:03:57 PM #

That has been fixed in the 1.01 release

harsha
harsha
4/7/2007 2:31:15 AM #

Mads,
Nope, I am still not able to get it work. Got the latest v1.01 though.

harsha
harsha
4/7/2007 2:36:02 AM #

Got it..The XML was cached. Restarted IIS and created browser, worked.

Comments are closed

About the author

Mads Kristensen

Mads Kristensen
Program Manager at the Microsoft Web Platform team and founder of BlogEngine.NET.

More...

Month List

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.