共用方式為


IMetadataInfo::GetModuleCoNtextContainer 方法

傳回中繼資料的內容容器。

語法

virtual IHttpModuleContextContainer* GetModuleContextContainer(  
   VOID  
) = 0;  

參數

此方法不會採用任何參數。

傳回值

IHttpModuleCoNtextContainer的指標。

備註

方法傳 GetModuleContextContainer 回值取決於實作。 根據預設,目前的實作會建立已同步但未分配的 IDispensedHttpModuleCoNtextContainer 介面。

實作者的注意事項

IMetadataInfo實作者負責使用此資料的記憶體管理;因此, IMetadataInfo 實作者應該在 IDispensedHttpModuleContextContainer 建構時建立指標,並保存 private 指標生命週期的 IMetadataInfo 這個 IDispensedHttpModuleContextContainer 指標參考。 當您呼叫 方法時 GetModuleContextContainer ,應該向上傳播並傳回這個相同的 IDispensedHttpModuleContextContainer 指標。 當您呼叫實 IMetadataInfo 作 介面之類別的解構函式時,此解構函式應該在此 private 參考上呼叫IDispensedHttpModuleCoNtextContainer::ReleaseContainer方法,然後將該參考設定為 Null。

GetModuleContextContainer 不應該傳回 Null。 如果內部容器為 Null,請在呼叫 IHttpServer::D ispenseContainer時將此內部容器設定為值,然後傳回這個相同的容器。

注意

雖然隱含向上傳播作業被視為安全,但請考慮使用明確的轉換來厘清程式。 也請考慮盡可能使用 dynamic_cast 運算子。

來電者的附注

IMetadataInfo實作者負責使用此資料的記憶體管理;因此,當不再需要此資料時, IMetadataInfo 用戶端不得釋放、呼叫 delete 或嘗試關閉廣播,並在傳 IHttpModuleContextContainer 回的指標上呼叫 IDispensedHttpModuleContextContainer::ReleaseContainer

範例

下列程式碼範例示範名為 MyContainer 的自訂類別,該類別會實 IDispensedHttpModuleContextContainer 作 介面,以及名為 的自訂類別,該類別會 MyClass 實作 IMetadataInfo 介面。 MyClass 會在 MyContainer 指標的 MyClass 存留期期間管理指標。

// 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  
// IMetadataInfo interface.  
class MyClass : public IMetadataInfo  
{  
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 to an  
    // IDispensedHttpModuleContextContainer  
    // pointer for readability.  
    virtual IHttpModuleContextContainer*   
        GetModuleContextContainer(VOID)  
    {  
        return (IHttpModuleContextContainer*)m_container;  
    }  
  
    // Implement additional IMetadataInfo  
    // pure virtual methods if this class  
    // is not abstract.  
  
private:  
    // Specify a private  
    // IDispensedHttpModuleContextContainer  
    // pointer.  
    IDispensedHttpModuleContextContainer* m_container;  
};  

規格需求

類型 描述
Client - Windows Vista 上的 IIS 7.0
- Windows 7 上的 IIS 7.5
- Windows 8 上的 IIS 8.0
- Windows 10上的 IIS 10.0
伺服器 - Windows Server 2008 上的 IIS 7.0
- Windows Server 2008 R2 上的 IIS 7.5
- Windows Server 2012 上的 IIS 8.0
- Windows Server 2012 R2 上的 IIS 8.5
- Windows Server 2016上的 IIS 10.0
產品 - 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
標頭 Httpserv.h

另請參閱

IMetadataInfo 介面
IHttpApplication::GetModuleCoNtextContainer 方法
IHttpConnection::GetModuleCoNtextContainer 方法
IHttpCoNtext::GetModuleCoNtextContainer 方法
IHttpFileInfo::GetModuleCoNtextContainer 方法
IHttpFileMonitor::GetModuleCoNtextContainer 方法
IHttpSite::GetModuleCoNtextContainer 方法
IHttpUrlInfo::GetModuleCoNtextContainer 方法