IHttpApplication::GetModuleContextContainer Method

IHttpApplication::GetModuleContextContainer Method

IIS 7.0

Returns the module context container for the application.

virtual IHttpModuleContextContainer* GetModuleContextContainer(
   VOID
) = 0;

This method takes no parameters.

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

IHttpApplication implementers are responsible for memory management with this data; therefore, IHttpApplication implementers should create an IDispensedHttpModuleContextContainer pointer at construction and hold a private reference to this IDispensedHttpModuleContextContainer pointer for the life of the IHttpApplication pointer. When the GetModuleContextContainer method is called, you should upcast and return this same IDispensedHttpModuleContextContainer pointer. When the destructor of the class that implements the IHttpApplication interface is called, 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.

NoteNote:

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

IHttpApplication implementers are responsible for memory management with this data; therefore, IHttpApplication 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 IHttpApplication interface. MyClass manages a MyContainer pointer during the lifetime of a MyClass pointer.

// The MyContainer class implements the 
// IDispensedHttpModuleContextContainer interface.
class MyContainer : public IDispensedHttpModuleContextContainer
{
public:
    // 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.

private:
    // 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.
    ~MyContainer()
    {

    }

    // Specify a Boolean value for dispensing.
    bool m_dispensed;
};

// The MyClass class implements the
// IHttpApplication interface.
class MyClass : public IHttpApplication
{
public:
    // The MyClass method is the public
    // constructor for the MyClass class.
    MyClass()
    {
        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->ReleaseContainer();
        m_container = NULL;
    }

    // The GetModuleContextContainer method
    // returns an IHttpModuleContextContainer
    // pointer.
    // return: an explicit upcast 
    // IDispensedHttpModuleContextContainer
    // pointer for readability.
    virtual IHttpModuleContextContainer* 
        GetModuleContextContainer(VOID)
    {
        return (IHttpModuleContextContainer*)m_container;
    }
 
    // Implement additional IHttpApplication
    // pure virtual methods if this class
    // is not abstract.

private:
    // Specify a private
    // IDispensedHttpModuleContextContainer
    // pointer.
    IDispensedHttpModuleContextContainer* m_container;
};

Type

Description

Client

  • IIS 7.0 on Windows Vista

  • IIS 7.5 on Windows 7

  • IIS Express 7.5 on Windows XP, Windows Vista, Windows 7

  • IIS 8.0 on Windows 8 Client

Server

  • IIS 7.0 on Windows Server 2008

  • IIS 7.5 on Windows Server 2008 R2

  • IIS Express 7.5 on Windows Server 2003, Windows Server 2008, Windows Server 2008 R2

  • IIS 8.0 on Windows 8 Server

Product

IIS 7.0, IIS 7.5, IIS Express 7.5, IIS 8.0

Header

Httpserv.h

Community Additions

ADD
Show:
© 2016 Microsoft