IHttpModuleContextContainer Interface

IIS 7.0

Maintains a collection of IHttpStoredContext pointers.

class IHttpModuleContextContainer

The following table lists the methods exposed by the IHttpModuleContextContainer class.




Returns the stored context from the context container.


Sets the stored context on the context container.




Extends IHttpModuleContextContainer by providing functionality for releasing a container.

Many IIS 7 classes maintain a private IDispensedHttpModuleContextContainer pointer as a member variable. These classes implement various interfaces, including IHttpApplication, IHttpConnection, IHttpContext, IHttpFileInfo, IHttpSite, IHttpUrlInfo, and IMetadataInfo.

Each of these interfaces defines a GetModuleContextContainer method, which accepts no arguments and returns an IHttpModuleContextContainer pointer. When the various GetModuleContextContainer methods are called, most of these implementers return the private data as an upcast IHttpModuleContextContainer. This allows the interface implementers to expose custom containers while maintaining the lifetime of those containers.

You can define custom classes that implement the IHttpStoredContext interface and then create a pointer to this IHttpStoredContext class implementer by calling the new operator. You can then add and retrieve this pointer on an IHttpModuleContextContainer pointer by calling the SetModuleContext and GetModuleContext methods, respectively.

When the IHttpStoredContext pointer is no longer needed, the IHttpStoredContext::CleanupStoredContext method is called internally, where the implementer of the IHttpStoredContext interface method should usually call delete this.


While it may be a safe operation to downcast an IHttpModuleContextContainer to an IDispensedHttpModuleContextContainer by using the dynamic_cast operator, you should avoid performing this cast. The IDispensedHttpModuleContextContainer interface adds only one method, ReleaseContainer, to its base interface, and this method should be called only internally.

In some cases, an IHttpModuleContextContainer pointer may be downcast to an IDispensedHttpModuleContextContainer interface to access extended behavior.


Before performing any downcast operation, always verify that the cast is correct to guarantee correct program behavior.


Consider using the dynamic_cast operator whenever possible when you perform a downcast operation.


The following code example demonstrates how to create a global module that listens for GL_TRACE_EVENT events and then writes custom IHttpStoredContext information to the Event Viewer.


IIS 7 generates a large number of events in the Event Viewer. To avoid a log overflow error in a production environment, you should generally avoid writing cache information to the event log. For demonstration purposes, this code example writes an entry to the Event Viewer in debug mode only.

The above code writes a new event to the Event Viewer, where the Data box contains consecutive strings similar to the following.


Your module must export the RegisterModule function. You can export this function by creating a module definition (.def) file for your project, or you can compile the module by using the /EXPORT:RegisterModule switch. For more information, see Walkthrough: Creating a Request-Level HTTP Module By Using Native Code.

You can optionally compile the code by using the __stdcall (/Gz) calling convention instead of explicitly declaring the calling convention for each function.





  • IIS 7.0 on Windows Vista

  • IIS 7.5 on Windows 7

  • IIS 8.0 on Windows 8

  • IIS 10.0 on Windows 10


  • IIS 7.0 on Windows Server 2008

  • IIS 7.5 on Windows Server 2008 R2

  • IIS 8.0 on Windows Server 2012

  • IIS 8.5 on Windows Server 2012 R2

  • IIS 10.0 on Windows Server 2016 Technical Preview


  • IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0

  • IIS Express 7.5, IIS Express 8.0, IIS Express 10.0