Skip to main content
ATL Server Library Reference 
Session-State Services in ATL Server 

ATL Server provides two separate implementations for session-state management. One implementation uses memory to store session-state data, and the other implementation uses a database. If neither implementation meets your needs, you can design a custom implementation that works seamlessly through the provided session-state interfaces. Regardless of implementation, the ISAPI extension DLL provides session-state support.

Within ISAPI extension DLL code, session-state support takes the form of a CSessionStateService instance, which is added as a data member to a CIsapiExtension-derived class. The specific session-state implementation (memory, database, or custom) is determined by a template argument passed to the CSessionStateService class. For memory-based session support, use the CMemSessionServiceImpl class. For database support, use the CDBSessionServiceImpl class. The following example code declares an instance of CSessionStateService that uses the database-backed session-state implementation:

typedef CSessionStateService<CWorkerThread<>, CDBSessionServiceImpl> sessionSvcType;
CComObjectGlobal<sessionSvcType> m_SessionStateSvc;;

A custom implementation requires you to define the class that you provide as the template argument used to specialize CSessionStateService. Regardless of the implementation class used, the resulting CSessionStateService object is used by the CIsapiExtension-derived class to service session-state requests made by application DLLs. See Session-State Tasks for instruction on how to add session-state support to ISAPI extension DLLs that were not generated with built-in session-state support.

Writing Custom Implementations

To provide a custom session-state implementation, write a class that supports these methods:

  • HRESULT CreateNewSession(LPSTR szNewID, DWORD *pdwSize, ISession** ppSession);

    The CreateNewSession method will be called whenever an application DLL requests a new session. The arguments are identical to those of the ISessionStateService::CreateNewSession method.

  • HRESULT GetSession(LPCSTR szID, ISession **ppSession);

    The GetSession method will be called whenever an application DLL requests an existing session. The arguments are identical to those of the ISessionStateService::GetSession method.

  • HRESULT CloseSession(LPCSTR szID);

    The CloseSession method will be called whenever an application DLL requests that a session be removed. The single argument is the session ID.

  • void SweepSessions();

    ATL Server calls the SweepSessions method periodically to provide an opportunity for the implementation to purge expired sessions. Depending on your implementation, it may be acceptable to provide only an empty method body.

  • HRESULT SetSessionTimeout(unsigned __int64 nTimeoutMS) throw();

    The SetSessionTimeout method will be called when the application DLL specifies a timeout value to be used for all sessions.

  • HRESULT GetSessionTimeout(unsigned __int64* pnTimeout);

    The GetSessionTimeout method should provide the global session timeout value.

  • HRESULT GetSessionCount(DWORD *pnCount);

    The GetSessionCount method should provide the number of sessions that are currently active.

  • void ReleaseAllSessions() throw();

    The ReleaseAllSessions method should remove all sessions. This method is called immediately before the ISAPI extension DLL terminates.

  • HRESULT Initialize(void*, DWORD, IServiceProvider*);

    The Initialize method is called when the ISAPI extension DLL starts and should be used to initialize implementation-specific data structures. The Initalize method arguments are implementation specific. The ATL Server database session-state implementation, for example, uses these arguments to provide the implementation with database connection information.

See Also