|
Recent
Articles |
New Blog Engine Written In ASP.NET 1.1 For more than a year, I've been blogging on the excellent dasBlog engine and it has been good. I really like the fact that it runs on XML instead of a database. However, it is written in ASP.NET 1.1 and is quite...
ASP.NET: Count Clicks On External Links On a small test website I'm building in my spare time, I wanted a way to count the number of clicks to the outgoing links from that site. Imaging hosting banners or other affiliate links where you get paid per click...
Creating Reusable User Controls In ASP.NET In almost every web project of any size, you would probably use a lot of user controls to separate the content and UI logic. Many of the user controls are used only at one place in the solution while others are used by various pages and other user controls. The ones...
ASP.NET: Is It Too Easy? Some time ago, I wrote a post called "Is ASP.NET too difficult?" and I strongly believe that it is.
Yet at the same time it cause problems by making it too easy to do relative advanced programming. It doesn't seem...
ASP.NET: Make GridView Control Accessible The GridView is a new web control in ASP.NET 2.0 and is an improvement of the old DataGrid. One of the biggest issues with the DataGrid was the lack of standard compliance and accessibility. This has been fixed...
ASP.NET - Block IP Addresses From Your Site Recently, one of my readers asked me how to block certain IP addresses from accessing his ASP.NET website. It was a good question that could be answered in multiple correct ways. My answer was a plug 'n...
ASP.NET: Maintain Scroll Position After Postbacks To maintain the scroll position after postbacks is important for larger web pages in order to let the user know exactly what is going on. It is good usability and something you would expect in modern web...
|
|
|
04.06.07
BlogEngine.NET: Events In The File & Image Handlers
By
Mads Kristensen
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.
Comments
About the Author: Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.
http://www.madskristensen.dk/
|