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
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
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.
Hashtable allViewStateData = cache.SearchService.GetByTag(new 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