Accessing HttpRequest from Global.asax via a page

Posted by Polymorphix on Stack Overflow See other posts from Stack Overflow or by Polymorphix
Published on 2010-06-14T10:27:41Z Indexed on 2010/06/14 10:32 UTC
Read the original article Hit count: 279

Filed under:
|

I'm trying to get a property (ImpersonatePersonId) from a page in global.asax but get a HttpException saying 'Request is not available in this context'.

I've been searching for some documentation on where in the pipeline the request is accessible, but as far as I can see all Microsoft can produce of documentation is one-liners like "PostRequestHandlerExecute: Occurs when the ASP.NET event handler finishes execution." which really doesn't give me much...

I've tried placing the call in both Pre and PostRequestHandlerExceute but with the same result.

I wonder if anyone with experience in this would be so kind as to tell me where the Request object is available.

My code from global asax is below.

ICanImpersonate page = HttpContext.Current.Handler as ICanImpersonate;
ImpersonatedUser impersonatePerson = page != null ? page.ImpersonatePersonId : null;
Response.Filter = new TagRewriter(Response, new TagProcessor(Context, impersonatePerson).Process);

What I want to do is rewrite some HTML based on some request parameters.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about global-asax