Here are some follow-up links and answers to questions from our geekSpeak November 28th on HTTP Handlers and Modules with Chris Love. You can catch the recording on Channel 9 here - geekSpeak recording - httpHandlers and httpModules with Chris Love


An end-to-end IIS extensibility demo -

Documentation on the iHTTPModule interface

The link to the blog post with the downloads from the demos

Nathan Good’s RegEx book

Zain Naboulsi’s in-depth webcast series  on RegEx

Unanswered questions from the webcast:

How do you process other http verbs outside of get and post, can you do that with pages or do you need a handler?

Yes, this is the documentation on the httpHandlers element,

The add sub element, which allows for a comma separate list of verbs,

A good common example:

<add verb="GET,HEAD, PUT" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>

When should we create a HttpModule vs. adding code to the Global.asax? Pros/Cons?

The first rule I look at is do I want to reuse this code across multiple sites, if yes, then I want a custom httpModule in a class library. Then I have to ask if the Global.ASAX provides access to the event I want to intercept or if I can actually write the best code in the global file. Often I will start working the code in the global file and eventually move it to a custom handler. I believe handlers actually perform better (however we are talking milliseconds) than the global file. I would not look down at one who just used the global file for all module routines!

One can make endless settings in web.config. Is there a reference of what to and how to configure in web.config?

Configuration section reference -

Can HttpModule across multiple WebApps on same server?

Make them in a class library and add it to the GAC, then register the module or handler in the web.config file.

Does the http module need to be thread safe, and does it stay in memory ready to run - can the live be specified?

Well by default it is placed in memory the first request made to the site. The methods are tied to the thread processing the request, which handles the threading for us. Now you could run into the scenario where you have an application variable that can be touched by each request. A counter would be common and I would lock that variable when changing the value.

Where should I look if the HttpContext from the Web application is not being passed to an HttpHandler?

It is passed by default. The ProcessRequest method is called to when the handler is invoked and it takes a reference to the current httpContext, so from there you can access anything you need.

Technorati tags: ,