- Posted by Shay Friedman on December 7, 2009
Http handlers is a really elegant infrastructure allowing you to provide special behavior to specific paths in your application. You can use them to create RSS feeds, dynamically generate images, handle requests differently and more.
Apart from writing new http handlers, there are some built-in handlers that you can take advantage of. The built in handlers are separated into three categories (in my opinion at least): request handlers, error generators and misc. handlers.
Request Handlers
These handlers process requests in a specific way. Although these already have paths configured for them, you can manually configure them in the web.config (or via IIS Manager) to run on different paths. For example, treat ABC files the same as ASPX files. There is one catch here – because ASPX, ASHX and ASMX files are dynamically compiles, you will also need to provide build configurations for the new extensions.
The handlers in this category include:
- The regular ASP.NET page (ASPX) hander - System.Web.UI.PageHandlerFactory.
- The generic handler (ASHX) handler - System.Web.UI.SimpleHandlerFactory.
- The resource handler (WebResource.axd) - System.Web.Handlers.AssemblyResourceLoader.
- The web service handler (ASMX) - System.Web.Services.Protocols.WebServiceHandlerFactory.
- The trace handler (trace.axd) – System.Web.Handlers.TraceHandler.
The following web.config sample enables accessing trace info via MyTrace.aaa (this is web.config configuration for IIS 7 running in Integrated mode, in other versions or modes the configuration will be a bit different):
After this is configured (and tracing is enabled as well), try navigate to MyTrace.aaa page.
Error Generators
These handlers generate specific http errors. You can use them to prevent access to specific files, specific extensions or folders. These error generator handlers include:
- Forbidden – generates a 403 Forbidden http error - System.Web.HttpForbiddenHandler.
- Not Found – generates a 404 Not Found http error - System.Web.HttpNotFoundHandler.
- Method Not Allowed – generates a 405 Method Not Allowed http error - System.Web.HttpMethodNotAllowedHandler.
- Not Implemented – generates a 501 Not Implemented http error - System.Web.HttpNotImplementedHandler.
The following web.config sample prevents users from accessing all files with secret extensions. Once a user tries to access such file he or she will get a 403 Forbidden page:
<system.webServer>
<handers>
<add verb="*" path="*.secret" name="SecretAccess" type="System.Web.HttpForbiddenHandler"/>
</handlers>
</system.webServer>
Try navigating to top.secret and witness the result.
Miscellaneous
The misc. category contains one handler, the static file handler, which can help in various scenarios. It will present the file content without any processing. With this handler you can, for example, enable users to retrieve lkr file (no special meaning to this extension that I know of) content.
- Static file – shows the content of a file without any processing - System.Web.StaticFileHandler.
The following sample configures lkr files to be processed by the static file handler. To test this, create a txt file in your web application root folder, rename its extension to lkr and navigate to it.
<system.webServer>
<handlers>
<add verb="*" path="*.lkr" name="lkr-handler"
type="System.Web.StaticFileHandler" resourceType="File"/>
</handlers>
</system.webServer>
All the best,
Shay.
Share it:

- Posted by Shay Friedman on December 1, 2009
This post has started from my suffering from developing web sites differently to make them work in IE and in Firefox the same. That was everything I asked for…Currently, even with IE8 I still can’t develop on Firefox and remain calm and confident that the site works the same on IE.
The truth is that it is not entirely Microsoft’s fault. When they begun developing IE somewhere in 1995, standards were not that important – it was more about “please just work” kind of work. In addition, even if there were standards, we can assume that the guys at Microsoft assumed that they would change the standards as they had done before in other fields. What Microsoft didn’t realize was that the Internet was stronger and that they were not going to win the standards battle this time.
Anyway, out of my suffering I came to a conclusion – even though we like to think of Microsoft as this big evil doer that doesn’t follow standards, it is just another brick in the wall of global un-standardization that started long long ago and still effects our everyday life.
Language – yes, language. Starting from the beginning of days, the very basic resource of our communication is a one big un-standard thing. Just visit the country near you (and sometimes even the district near you) and most likely you will run into a different language than yours. Think of how big it is – almost everything you create in one country, should be fixed in some way to fit a second country. TV shows, manuals, books, user interfaces, etc.
If you do not agree with me because language is related to culture and different cultures is a part of our nature (some would say that it’s a kind of un-standardization, too), the next bullet will be harder for you to disprove.
Signs – especially driving signs. This is something which is entirely unrelated to the local culture. We all should stop at the traffic light, slow when entering school perimeter and beware of rolling stones. As a result, driving rules across the globe are very similar indeed. However, every country uses a slightly different sign set. For example, look at the different Stop signs from across the globe:




If we had to develop a globalized application that involves driving signs, we had to create local versions for each country – very similar to writing code for IE and for Firefox…
Driving direction – that always amazes me. The world is split to about 34% live in right hand traffic countries and 66% live in left hand traffic countries (according to Wikipedia). This is such a big historical standard failure! it forces car companies to produce different versions of cars to meet both standards!
In London it’s funny to see drivers from other EU countries driving their right-sided cars and trying to understand how to enter the roundabout. Actually it’s not that funny if they enter the roundabout in the wrong direction – life can be lost! and it’s all because of un-standardization…
The IE vs. FF issue seems less important now, doesn’t it?
Electricity – the differences in electricity methods around the world is astonishing – 110W, 220W, plug with 2 holes, with 3 holes, with wide holes, with thin holes…… huh? why?






It’s like every country developed electricity by itself and didn’t tell the others until they developed it as well. do I hear someone say “Microsoft and Netscape!”?
In conclusion, our world is full of un-standardization – from the language we talk to Internet development. There are much more examples than the ones I’ve brought here – shoe and shirt sizes, Km and Miles, Kg and Pounds, Meters and Feet, money and more. Although it might be upsetting to meet all standards it also has one big advantage – it creates so many jobs! consequently it helps the world’s economy!
So Microsoft actually helps the world. Yes.
All the best,
Shay.