IHttpContext::GetModuleContextContainer Method

Retrieves the module context container for the current context.


virtual IHttpModuleContextContainer* GetModuleContextContainer(  
) = 0;  


This method takes no parameters.

Return Value

A pointer to an IHttpModuleContextContainer interface.


The GetModuleContextContainer method return value depends on implementation. By default, the current implementation creates an IDispensedHttpModuleContextContainer interface that is synchronized but not dispensed.

Notes for Implementers

IHttpContext implementers are responsible for memory management with this data; therefore, IHttpContext implementers should create an IDispensedHttpModuleContextContainer pointer at construction and hold a private reference to this IDispensedHttpModuleContextContainer pointer for the life of the IHttpContext pointer. When you call the GetModuleContextContainer method, you should upcast and return this same IDispensedHttpModuleContextContainer pointer. When you call the destructor of the class that implements the IHttpContext interface, this destructor should call the IDispensedHttpModuleContextContainer::ReleaseContainer method on this private reference and then set that reference to NULL.

GetModuleContextContainer should not return NULL. If the internal container is NULL, set this internal container to the value on the call to IHttpServer::DispenseContainer, and then return this same container.


Although implicit upcast operations are considered safe, consider using an explicit cast for program clarity. Also consider using the dynamic_cast operator whenever possible.

Notes for Callers

IHttpContext implementers are responsible for memory management with this data; therefore, IHttpContext clients must not release, call delete on, or attempt to downcast and call IDispensedHttpModuleContextContainer::ReleaseContainer on the returned IHttpModuleContextContainer pointer when this data is no longer needed.


The following code example demonstrates a custom class named MyContainer that implements the IDispensedHttpModuleContextContainer interface, and a custom class named MyClass that implements the IHttpContext interface. MyClass manages a MyContainer pointer during the lifetime of a MyClass pointer.

// The MyContainer class implements the   
// IDispensedHttpModuleContextContainer interface.  
class MyContainer : public IDispensedHttpModuleContextContainer  
    // The MyContainer method is the public  
    // constructor for the MyContainer class.  
    // Make this method protected if the   
    // MyContainer class is abstract.  
    // dispensed: true if the container should  
    // call delete this when the ReleaseContainer  
    // method is called.  
    MyContainer(bool dispensed = false)   
        : m_dispensed(dispensed)  
    // The ReleaseContainer method   
    // calls delete this if this container  
    // is dispensed.  
    virtual VOID ReleaseContainer(VOID)  
        if (m_dispensed)  
            delete this;  
    // Implement additional   
    // IDispensedHttpModuleContextContainer  
    // pure virtual methods if this class  
    // is not abstract.  
    // The MyContainer method is the private  
    // destructor for the MyContainer class.  
    // Make this method protected and virtual   
    // if the MyContainer class expects   
    // to be a class of derivation. This method   
    // should not be public because   
    // IDispensedHttpModuleContextContainer pointers  
    // should be disposed externally only by   
    // calling the ReleaseContainer method.  
    // Specify a Boolean value for dispensing.  
    bool m_dispensed;  
// The MyClass class implements the  
// IHttpContext interface.  
class MyClass : public IHttpContext  
    // The MyClass method is the public  
    // constructor for the MyClass class.  
        m_container = new MyContainer;  
    // The MyClass method is the   
    // public virtual destructor   
    // for the MyClass class. This destructor  
    // calls ReleaseContainer on the internal  
    // IDispensedHttpModuleContextContainer  
    // pointer and sets that pointer to NULL.  
    virtual ~MyClass()  
        m_container = NULL;  
    // The GetModuleContextContainer method  
    // returns an IHttpModuleContextContainer  
    // pointer.  
    // return: an explicit upcast   
    // IDispensedHttpModuleContextContainer  
    // pointer for readability.  
    virtual IHttpModuleContextContainer*   
        return (IHttpModuleContextContainer*)m_container;  
    // Implement additional IHttpContext  
    // pure virtual methods if this class  
    // is not abstract.  
    // Specify a private  
    // IDispensedHttpModuleContextContainer  
    // pointer.  
    IDispensedHttpModuleContextContainer* m_container;  


Type Description
Client - IIS 7.0 on Windows Vista
- IIS 7.5 on Windows 7
- IIS 8.0 on Windows 8
- IIS 10.0 on Windows 10
Server - 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
Product - 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
Header Httpserv.h

See Also

IHttpContext Interface
IHttpApplication::GetModuleContextContainer Method
IHttpConnection::GetModuleContextContainer Method
IHttpFileInfo::GetModuleContextContainer Method
IHttpFileMonitor::GetModuleContextContainer Method
IHttpSite::GetModuleContextContainer Method
IHttpUrlInfo::GetModuleContextContainer Method
IMetadataInfo::GetModuleContextContainer Method