Bagikan melalui


IDispensedHttpModuleContextContainer::ReleaseContainer Method

Menghapus kontainer konteks jika dilenyapkan.

Sintaks

virtual VOID ReleaseContainer(  
   VOID  
) = 0;  

Parameter

Metode ini tidak memerlukan parameter.

Keamanan Thread

Metode ReleaseContainer ini tidak aman untuk pelaksana yang dispensasi.

Keterangan

Perilaku metode ini tergantung pada implementasinya. Anda harus menggunakan informasi berikut sebagai pedoman, tetapi mungkin tidak benar dalam semua skenario:

  • Sebagian besar pelaksana mendeklarasikan nilai privat Boolean bernama dispensed; nilai defaultnya adalah false dan perilaku defaultnya adalah tidak dispensed pernah diatur ke true. Namun, jika implementasi telah diatur dispensed ke true, ketika ReleaseContainer dipanggil, penunjuk IDispensedHttpModuleContextContainer memanggil delete dirinya sendiri. Jika tidak, ReleaseContainer adalah operasi kosong.

  • Jika delete dipanggil, IDispensedHttpModuleContextContainer menghitung array internal penunjuk IHttpStoredContext dan memanggil metode IHttpStoredContext::CleanupStoredContext pada pointer apa pun yang ditambahkan sebelumnya dengan menggunakan metode IHttpModuleContextContainer::SetModuleContext . Kontainer konteks kemudian membuang memori array pada heap dan mengatur array tersebut ke NULL.

Contoh

Contoh berikut menunjukkan kelas kustom bernama MyContainer yang mengimplementasikan IDispensedHttpModuleContextContainer antarmuka. Ini juga menunjukkan kelas kustom bernama MyClass yang mengimplementasikan metode bernama GetModuleContextContainer. MyClassMyContainer mengelola pointer selama masa MyClass pakai 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;  
};  
  
// Create the MyClass class.  
class MyClass  
{  
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: a static upcast   
    // IDispensedHttpModuleContextContainer.  
    virtual IHttpModuleContextContainer*   
        GetModuleContextContainer(VOID)  
    {  
        return static_cast<IHttpModuleContextContainer*>  
            (m_container);  
    }  
  
    // Implement additional IHttpUrlInfo  
    // pure virtual methods if this class  
    // is not abstract.  
  
private:  
    // Specify a private  
    // IDispensedHttpModuleContextContainer  
    // pointer.  
    IDispensedHttpModuleContextContainer* m_container;  
};  

Persyaratan

Jenis Deskripsi
Klien - IIS 7.0 di Windows Vista
- IIS 7.5 di Windows 7
- IIS 8.0 di Windows 8
- IIS 10.0 pada Windows 10
Server - IIS 7.0 di Windows Server 2008
- IIS 7.5 di Windows Server 2008 R2
- IIS 8.0 di Windows Server 2012
- IIS 8.5 di Windows Server 2012 R2
- IIS 10.0 di Windows Server 2016
Produk - 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

Lihat juga

Antarmuka IDispensedHttpModuleContextContainer
Metode IHttpApplication::GetModuleContextContainer
Metode IHttpConnection::GetModuleContextContainer
Metode IHttpContext::GetModuleContextContainer
Metode IHttpFileInfo::GetModuleContextContainer
Antarmuka IHttpModuleContextContainer
Metode IHttpSite::GetModuleContextContainer
Metode IHttpUrlInfo::GetModuleContextContainer
IMetadataInfo::GetModuleContextContainer Method