Special Considerations Regarding Web Applications

By default, session-state values and information are stored in memory within the ASP.NET process. ASP.NET also provides session-state providers that allow you to use a session-state server that keeps session data in a separate process, or you can persist session state data to a SQL database. However, with ASP.NET 2.0, you can create custom session-state providers that allow you to customize how session-state data is stored in your ASP.NET applications.

Coherence for .NET includes a custom SessionStateStoreProvider implementation that uses a Coherence cache to store session state. This makes Coherence for .NET the best solution for any large ASP.NET application running within a web farm. Other options in this scenario are to use the StateServer, which introduces a single point of failure for the whole web farm, or to use the SqlServerStateProvider, which theoretically can be clustered, but is extremely slow and scales only to a certain point. Also, unlike both StateServer and SqlServerStateProvider, the CoherenceSessionProvider supports Session.End event through cache events - only the InProc one supports this, but it cannot be used in a web farm environment.

The only requirement of the CoherenceSessionStore is that all objects stored in the session must be serializable (.NET serializable, not POF). This same requirement applies to both out-of-proc session stores provided by Microsoft, so modifying any existing ASP.NET 2.0 application that uses StateServer or SqlServerStateProvider to use the CoherenceSessionStore is as simple as adding the following to the Web.config file:

<sessionState mode="Custom" customProvider="CoherenceSessionProvider" timeout="20">
    <providers>
        <add name="CoherenceSessionProvider" type="Tangosol.Web.CoherenceSessionStore, Coherence" cacheName="dist-session-cache"/>
    </providers>
</sessionState>

Note that no code changes are required within the application itself.

If your web application uses Coherence for .NET (either directly, via the CoherenceSessionProvider, or both), you must remember to call CacheFactory.shutdown() when your application terminates. To make this easier, Coherence for .NET includes an HTTP module that will automatically call CacheFactory.shutdown() when your web application exits. To use the CoherenceShutdownModule simply include it in your Web.config file:

<httpModules>
  <add name="CoherenceShutdown" type="Tangosol.Web.CoherenceShutdownModule, Coherence"/>
</httpModules>