views:

814

answers:

3

Hi, I'm trying to access a Page within an HttpModule and I think I should do this by calling HttpContext.Current.Handler (This should reference the current page) but I'm getting null all the time.

I'm developing using .Net 3.5 framework.

I'm checking this on AuthorizeRequest and AuthenticateRequest

Thanks.

+2  A: 

Probably, the request has not been handed out to a handler yet (for example, you're in BeginRequest).

Mehrdad Afshari
I'm checking on AuthorizeRequest and AuthenticateRequest
Paleta
@Paleta: You can't check it there. Handler will be selected after request is authenticated/authorized. You can check it in `PostMapRequestHandler` event and later.
Mehrdad Afshari
A: 

In what method are you accessing this property?

In IHttpModule.Init, it will be null. You need to register event handlers on the application received as a parameter to the Init method and do your work there.

SLaks
I'm checking on AuthorizeRequest and AuthenticateRequest
Paleta
+1  A: 

In AuthorizeRequest and AuthenticateRequest, the handler has not been created yet. (A handler should not be created if the request is denied) Therefore, this property is null.

Why do you the Page, and what are you trying to do?

You could try handling PostMapRequestHandler, which occurs after it resolves the Page, and throwing an HttpException or calling Response.End if you decide to deny the request.

However, please note that to get an instance of the handler, its constructor must run; make sure it doesn't do anything critical or sensitive.

SLaks