views:

883

answers:

3

I have an ASP.Net application and I've noticed through using profilers that there is a sizable amount of processing that happens before my page even runs. In my application, we don't used viewstate, asp.Net session, and we probably don't require most of the overhead that comes of a consequence of using the asp.net page lifecycle. Is there some other class I can easily inherit from that will cut out all the Asp.Net stuff, and just let my handle writing to the page by myself?

I've heard that ASP.Net MVC can cut down page loads considerably, simply because it doesn't use the old asp.net lifecycle, and handles pages differently. Is there an easy way, maybe by simply having my web pages inherit some other class to take advantage of something like this. I would like a solution that works in ASP.Net 2.0 if at all possible.

+3  A: 

If you don't need all this "asp.net stuff", you may wish to implement a custom IHttpHandler. Afaik, there are no other standard IHttpHandlers to reuse except the Page class.

amartynov
+6  A: 
Allen
A: 

To do this you should start by looking at the System.Web.UI.PageHandlerFactory class and the corresponding System.Web.IHttpHandlerFactory interface.

From there you will probably look at the System.Web.IHttpHandler inferface and the System.Web.UI.Page class.

Basically you will write your own IHttpHandlerFactory that generates IHttpHandlers that handles the page requests.

Rune Grimstad
Is this step optional? Everything on msdn written about this is geared towards making handlers to support custom extension like *.sample rather than *.aspx. Just curious, thanks
Allen
In the simplest case you don't need an IHttpHandlerFactory, for you can register a single IHttpHandler that handles all requests to a file type. By implementing an IHttpHandlerFactory you can look at the request and return different implementations as needed.
Rune Grimstad
... This is what ASP.Net does using the PageHandlerFactory. Based on the requested url it will return an IHttpHandler that is implemented in the Page class with the same name. So instead of having one IHttpHandler that handles all requests to a file type you can have many.
Rune Grimstad