IHttpUrlInfo::GetModuleCoNtextContainer 方法
傳回 URL 特定資訊的內容容器。
語法
virtual IHttpModuleContextContainer* GetModuleContextContainer(
VOID
) = 0;
參數
此方法不會採用任何參數。
傳回值
IHttpModuleCoNtextContainer的指標。
備註
方法傳 GetModuleContextContainer
回值取決於實作。 根據預設,目前的實作會建立已同步但未分配的 IDispensedHttpModuleCoNtextContainer 介面。
實作者的注意事項
IHttpUrlInfo實作者負責使用此資料的記憶體管理;因此, IHttpUrlInfo
實作者應該在 IDispensedHttpModuleContextContainer
建構時建立指標,並保存 private
指標生命週期的 IHttpUrlInfo
這個 IDispensedHttpModuleContextContainer
指標參考。 當您呼叫 方法時 GetModuleContextContainer
,應該向上廣播並傳回這個相同的 IDispensedHttpModuleContextContainer
指標。 當您呼叫實作 IHttpUrlInfo
介面之類別的解構函式時,這個解構函式應該在此參考上 private
呼叫IDispensedHttpModuleCoNtextContainer::ReleaseContainer方法,然後將該參考設定為 Null。
GetModuleContextContainer
不應該傳回 Null。 如果內部容器為 Null,請將這個內部容器設定為 呼叫 IHttpServer::D ispenseContainer的值,然後傳回這個相同的容器。
注意
雖然隱含的上播作業被視為安全,但請考慮使用明確轉換來讓程式清楚起見。 也請考慮盡可能使用 dynamic_cast 運算子。
來電者的注意事項
IHttpUrlInfo
實作者負責使用此資料的記憶體管理;因此,當不再需要此資料時, IHttpUrlInfo
用戶端不得釋放、呼叫 delete
或嘗試在傳回的 IHttpModuleContextContainer
指標上呼叫 IDispensedHttpModuleContextContainer::ReleaseContainer
。
範例
下列程式碼範例示範名為 的自訂類別,該類別會 MyContainer
實 IDispensedHttpModuleContextContainer
作 介面,以及名為 的自訂類別,該類別會 MyClass
實作 IHttpUrlInfo
介面。 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
// 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;
};
規格需求
類型 | 描述 |
---|---|
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 |
另請參閱
IHttpUrlInfo 介面
IHttpApplication::GetModuleCoNtextContainer 方法
IHttpConnection::GetModuleCoNtextContainer 方法
IHttpCoNtext::GetModuleCoNtextContainer 方法
IHttpFileInfo::GetModuleCoNtextContainer 方法
IHttpFileMonitor::GetModuleCoNtextContainer 方法
IHttpSite::GetModuleCoNtextContainer 方法
IMetadataInfo::GetModuleCoNtextContainer 方法