I’m getting that exception when I try to access the HttpContext.Current.Request object.
I’ve seen the responses in l1, l2 and l3 … so… my question then is :
For what in the world are IHttpModules now for?
I wanted to develop a module that gets hit every time a call enter to may website, so I can log the url accessed, the user IP address, etc… , but now it seems I cannot do it anymore in IIS7. Is there any workaround? (besides switch to “Classic Mode”).
alt text http://userserve-ak.last.fm/serve/126/24432467.jpg
Cheers.
When are you doing that? is it in a module event?
It should be perfectly doable in an integrated pool as well.
Bottom-line there are changes on how ASP.NET hooks to IIS when running in Integrated mode that makes it “more first class”. This does mean that certain events fire before, for example Application_Start will now fire outside the context of an actual request. Other examples are expecting to have a Windows Authenticated Identity in the BeginRequest, since now BeginRequest happens even before IIS authenticates, which was not the case in the past.
If your application depends on the old bad behavior you can still change your AppPool to run in Classic Mode and it will work just fine.
You should be able to grab the Request in any notifications that are request specific such as BeginRequest, EndRequest, PostAuthorizeRequest, etc.
Also, I would recommend against using HttpContext.Current since that incurs an additional look up in a hash table and usually you can get the context directly in other ways, specially in the context of a module, so for example if you handle the BeginRequest, you should be able to do:
and you will save the lookup.
From your description it sounds like you should be implementing a module that handles BeginRequest and EndRequest and you should be fine.