views:

337

answers:

1

I've got a custom IHttpModule that does authentication (to Facebook, Myspace, etc). It raises an event that can be handled in the HttpApplication instance with details about the user. It's a lot like the OnAuthenticate event that the FormsAuthenticationModule raises.

From the HttpApplication class, where should I place this information I get so it is available to the ASP.NET MVC pipeline? I used to stick it in the Context.Items dictionary. But it seems with the (much friendlier) HttpContextBase I want to put it there so that it's easy to mock/inject and I'm not using HttpContext.Current in my controller.

So, basically, how do I best get data from an IHttpModule into the MVC context? The best I could come up with from a quick look is to create a custom IControllerFactory to pull data out of the HttpContext and add it to the RequestContext. Did I answer my own question? Is there a less intrusive way (like an event I can handle)?

A: 

My guess is that your module runs before Routing. If so, then it's too early to add it to the RequestContext directly.

I would try adding it to HttpContext.Current.Items. Routing will wrap that HttpContext with an HttpContextBase. You should then be able to access it from anywhere via RequestContext.HttpContext.Items.

Haacked
I see, so items are copied from the HttpContext to the HttpContextBase. Good to know.
JD Conley