Friday, February 11, 2011

IHttpHandlerFactory

Last week i had to work with a specific scenario in ASP.net web application.

I created a new file type with an extension of *.xkb, so in order to handle this file in a specific way i created a HTTPHandler too. That was working perfectly as i expected.

The twist to the scenario came in, where I had to process /Handle the *.xkb file in two different way based on few querystring/Cookie value. This can be easily be done in the same handler itself. But I afraid the code will become messy. Hence the best approch that i envisioned was to use a IHttpHandlerFactory.So that in the GetHandler method of IHttpHandlerFactory will act as a factory class which will create appropriate HTTPHandler and return. So rather writing two different handling of *.xkb in same handler, i can use two different HttpHandlers (So the code is neat)and on one HTTPHandlerFactory.

No comments:

Post a Comment