Friday, May 23, 2008

Http Handlers

I have wanted to blog about HttpHandlers for a while now. At last I have found a reason, I have recently watched the DNRTV screencast 108 Miguel Castro on Http Handlers in .NET .

Http Handlers route file extensions to handlers. This is best illustrated by the fileC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config . If you open this file you will see something like this (abbreviated due to space constraints



















So when you browse to an aspx page

the aspx extension is routed to System.Web.UI.PageHandlerFactory handler
The page class interits from the control class, which is where we get the event cycles such as onLoad and onInit etc; and also implement IHttpHandler and this has a method called ProcessRequest.

You can't browse to a master page, The reason is seen

In this case the request is routed to HttpForbiddenHandler. This bring up a form that says you cannot browse to a master page.

The extension ashx is browsable point handler. Thus it is a web page without a ui and without the web page lifecycle. The key point is that the ashx can accept query strings.

No comments: