Try Playground
Show / Hide Table of Contents

Multi-site ASP.NET Session Caching [Deprecated]

NCache provides ASP.NET Session sharing support across multiple regions. This prevents users from losing their sessions in case traffic needs to be rerouted to another location, whether due to heavy traffic or disaster recovery. Sessions are replicated across WAN seamlessly without replicating the entire session which may result in increased bandwidth costs.

Multi Region ASP.NET Session Provider in NCache

Prerequisites

To utilize ASP.NET Session-State Provider in your application, install the AspNet.SessionState.NCache NuGet package by executing the following command in the Package Manager Console:

Install-Package AspNet.SessionState.NCache

Add New Section for ASP.NET Session-State Management

Modify the <configSections> section in the application's Web.config by adding the following section to enable session-state management. This tag must be the first child of the <configuration> tag:

<configSections>
    <section name="ncache" type="Alachisoft.NCache.Web.SessionStateManagement.NCacheSection,
    Alachisoft.NCache.SessionStateManagement, Version=x.x.x.x, Culture=neutral, PublicKeyToken=CFF5926ED6A53769"/>
</configSections>
Note

Replace "x.x.x.x" with the version of NCache you are using.

Modify Web.Config

Add a section with the name specified above (<ncache> in this case), under the <configuration> tag in your application's Web.config which will specify the locations for the primary and secondary caches:

<ncache>
  <sessionLocation>
    <primaryCache id="London_Cache" sid-prefix="LDNC"/>
    <secondaryCache id="NewYork_Cache" sid-prefix="NYKC"/>
    <secondaryCache id="Tokyo_Cache" sid-prefix="TKYC"/>
  </sessionLocation>
</ncache>

Modify sessionState Tag

Enable the custom sessionID manager using the sessionIDManagerType attribute of the sessionState element in Web.config and add a custom provider.

Member Description
sessionIDManagerType Optional String attribute. Specifies an identifier to make sure that the session Id remains unique in case multiple applications are using the same cache. Application ID should be the same for an application in a web farm. If no app Id is specified, nothing will be concatenated with the session Id.
<sessionState
cookieless ="false"
regenerateExpiredSessionId="true"
mode="Custom"
customProvider="NCacheSessionProvider"
timeout="60" sessionIDManagerType="Alachisoft.NCache.Web.SessionStateManagement.CustomSessionIdManager, Alachisoft.NCache.SessionStateManagement">
  <providers>
    <add name ="NCacheSessionProvider"
    type="Alachisoft.NCache.Web.SessionState.NSessionStoreProvider"
    sessionAppId="demoApp"
    cacheName="demoCache"
    writeExceptionsToEventLog="false"
    asyncSession="false"
    enableLogs="false"/>
  </providers>
</sessionState>
Note

It is not recommended to use the WriteExceptionsToEventLog tag in a Production environment.

  • When Location Affinity is enabled, cacheName specified in the <providers> section of Web.config will be ignored.
  • Cookieless sessions are not supported.

Additional Resources

NCache provides a sample application for NCache ASP.NET Sessions on GitHub.

See Also

.NET: Alachisoft.NCache.Web.SessionState namespace.

In This Article
  • Prerequisites
  • Add New Section for ASP.NET Session-State Management
  • Modify Web.Config
  • Modify sessionState Tag
  • Additional Resources
  • See Also

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Professional
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - 2025. All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top