Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

IHttpUrlInfo::GetModuleContextContainer Method

IIS 7.0

Returns the context container for the URL-specific information.

virtual IHttpModuleContextContainer* GetModuleContextContainer(
   VOID
) = 0;

This method takes no parameters.

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

IHttpUrlInfo implementers are responsible for memory management with this data; therefore, IHttpUrlInfo implementers should create an IDispensedHttpModuleContextContainer pointer at construction and hold a private reference to this IDispensedHttpModuleContextContainer pointer for the life of the IHttpUrlInfo 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 IHttpUrlInfo 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.

NoteNote:

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

IHttpUrlInfo implementers are responsible for memory management with this data; therefore, IHttpUrlInfo 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 IHttpUrlInfo 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
// IHttpUrlInfo interface.
class MyClass : public IHttpUrlInfo
{
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 IHttpUrlInfo
    // 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 Server 2012

Product

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

Header

Httpserv.h

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.