Try Playground
Show / Hide Table of Contents

ASP.NET View State Content Optimization Configuration

This page explains configurations for the NCache ViewState Content Optimization feature.

Prerequisites to Configure ASP.NET View State Content Optimization

  • .NET
  • Legacy API

To configure ASP.NET View State Content Optimization install the following NuGet packages in your application based on your NCache edition:

  • Enterprise: AspNet.ViewState.NCache
  • Professional: AspNet.ViewState.NCache.Professional
  • Create a new Console Application.
  • Make sure that the data being added is serializable.
  • Add NCache References by locating %NCHOME%\NCache\bin\assembly\4.0 and adding Alachisoft.NCache.Web and Alachisoft.NCache.Runtime as appropriate.

Configure View State Content Optimization

To use the content optimization feature of NCache with ASP.NET View State, you need to perform the following steps:

Step 1: Configure app_browser File

  • Create an app_browser file in the ASP.NET application. It will be created under the directory of app_browsers.

  • Now plug in page adapters in the app_browser file as follows:

<browsers>
<!-- NCache Plug page adapters in the app browser file as follows:. -->
   <browser refID="Default">
     <controlAdapters>
       <adapter controlType="System.Web.UI.Page"
       adapterType="Alachisoft.NCache.Adapters.PageAdapter">
     </controlAdapters>
   </browser>
</browsers>

Step 2: Configure Web.config File

  • Register the configuration section for View State in Web.config of your application:
<configSections>
    <sectionGroup name="ncContentOptimization">

      <section name= "settings"
               type="Alachisoft.NCache.ContentOptimization.Configurations.ContentSettings"
               allowLocation="true"
               allowDefinition= "Everywhere">
    </sectionGroup>
</configSections> 
  • Specify the settings for the registered config section:
<ncContentOptimization>
   <settings
            webAppId="ViewStateApp"
            enableViewstateCaching="true"
            groupedViewStateWithSessions="true"
            maxViewStatesPerSession="5"
            viewstateThreshold="1"
            cacheUriMapping="true"
            enableTrace="false"
            enableMetadataLocking="true"
            enableMinification="true"
            releaseLockInterval="5">

      <cacheSettings cacheName="demoCache" connectionRetryInterval="300">
            <expiration type="Absolute" duration="1" />
      </cacheSettings>

   </settings>
</ncContentOptimization>

Configuration Members

Following are the ASP.NET View State content optimization configuration Members:

Member Description
enableViewstateCaching Boolean value to enable /disable the View State Caching.
viewstateThreshold Sets the minimum threshold size of viewstate in bytes. Viewstates which are smaller than the threshold value will not be cached.
cacheUriMapping Cache URL mapping, default value is true.
enableTrace Enable/disable traces.
cacheName Name of the Cache.
connectionRetyInterval An interval after which a cache node tries to re-establish connection, default value is 300 seconds.
expiration Sets the expiration interval in minutes and expiration types either Sliding, Absolute or None.
duration Sets expiration interval in minutes.

Fetch View State Data

If the same cache is being used for ASP.NET View State Caching and other data, View State data can be retrieved by NC_ASP.net_viewstate_data tag. With this tag, it is easy to find the data specific to View State.

  • .NET
  • Legacy API
Hashtable allViewStateData = cache.SearchService.GetByTag(new Tag("NC_ASP.net_viewstate_data"));
Hashtable allViewStateData = cache.GetByTag(new Alachisoft.NCache.Runtime.Caching.Tag("NC_ASP.net_viewstate_data"));

The view state of a particular session can easily be retrieved from the cache based on sessionId.

See Also

Group View State with Session
Limit View State Caching
Page Level Grouping for View State
Distributed Cache for ASP.NET Output Caching
ASP.NET SignalR Backplane Overview

In This Article
  • Prerequisites to Configure ASP.NET View State Content Optimization
  • Configure View State Content Optimization
    • Step 1: Configure app_browser File
    • Step 2: Configure Web.config File
    • Configuration Members
  • Fetch View State Data
  • 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