Something between Page and IHttpHandler?

V

vimakefile

I'd like to have the concept of a Page (different code-behind file for
each url, session state, etc.) but be able to specify my own custom
HTTP payload.
(I don't want to use any Asp.Net forms, controls, etc.)
(Happens to be binary - but although I need to use HTTP, it's not going
to a browser.)
With IHttpHandler I lose Url->page mapping and sessions, but with Page
I don't have a way to override the HTTP processing, do I?

I'd expect that UI.Page would implement IHttpHandler with something
like:

public void ProcessRequest( System.Web.HttpContext context)
{
System.Web.UI.Forms.DefaultPageProcessor( context, this);
}

then I could just override this and everything would be fine.

Is there another class/interface I should be using, or another way to
hook HTTP-processing per-page??
Apologize ahead of time if I didn't RTFM enough.

thanks,
mike
 
S

Scott Allen

Hi Mike:

The handler asp.net chooses is configurable. So in the <httpHandlers>
section of machine.config you will see:

<add
verb="*"
path="*.aspx"
type="System.Web.UI.PageHandlerFactory"
/>

You can override the setting in your own web.config and implement your
own IHttpHandler derived handler.

Also, you may want to investigate using an .ashx extension. The
extension is mapped to a handler factory that will find your
IHttpHandler type and route the request to it - no config changes
required.
 
M

Mike

Thanks, Scott. I was aware of the handlers/factories -- I was hoping to
still be able to use a Page and override the HTTP processing on a
per-page basic so I could get URL mapping and session support. I guess
I'll have to roll my own...
I still don't know why the Page wasn't designed to deletegate its
processing so you could override the default reflection-based engine as
necessary.
 
K

Kevin Spencer

What makes you think you would lose Session? You can create an HttpHandler
that does everything a Page does (or not), and has access to the
HttpContext, just as a Page does. After all, a Page is just an
implementation of IHttpHandler. The guts of IHttpHandler is the
ProcessRequest() method:

void ProcessRequest(HttpContext context);

Note that the HttpContext, which includes Application, Session, etc. is
passed to the HttpHandler in this method.

You can read more about creaating HttpHandlers here:

http://msdn.microsoft.com/library/d...us/cpguide/html/cpconcreatinghttphandlers.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
K

Kevin Spencer

You don't need to override anything. You don't derive your HttpHandler from
Page. Implement IHttpHandler in your own class, and you're all set. The
implementation of the interface ensures that you will have the proper
methods to handle Requests. See my earlier reply for details.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
M

Matt Berther

Hello Kevin,
Note that the HttpContext, which includes Application, Session, etc.
is passed to the HttpHandler in this method.

Just to add to your point, the HttpContext has a non-null Session object
in your IHttpHandler only if you also implement either IRequireSessionState
or IReadOnlySessionState.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top