ASP.NET View State Content Optimization Configuration
Configure View State Content Optimization
The following steps need to be performed in order to use content optimization feature of NCache with View State:
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 page adapters in the app_browser file as following:
<browsers>
<!-- NCache Plug page adapters in the app browser file as following:. -->
<browser refID="Default">
<controlAdapters>
<adapter controlType="System.Web.UI.Page"
adapterType="Alachisoft.NCache.Adapters.PageAdapter">
</controlAdapters>
</browser>
</browsers>
Step 2: Configure Web.config File
Add the assembly reference for Alachisoft.NCache.Adapters
(located in %NCHOME%\integrations\ContentOptimization) in <compilation>
section of Web.config:
<compilation defaultLanguage="c#" debug="true" targetFramework= "4.0">
<assemblies>
<add assembly="Alachisoft.NCache.Adapters, Version=5.0.3, Culture=neutral, PublicKeyToken=CFF5926ED6A53769" />
<add assembly="Alachisoft.Common, Version=5.0.3, Culture=neutral, PublicKeyToken=CFF5926ED6A53769" />
<add assembly="Alachisoft.ContentOptimization, Version=5.0.3, Culture=neutral, PublicKeyToken=CFF5926ED6A53769" />
</assemblies>
</compilation>
Note
Replace Version=x.x.x.x with the actual NCache version that you have installed.
- 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 enableViewstateCaching="true"
viewstateThreshold="1"
cacheUriMapping="true"
enableTrace="false"
enableMinification="true" >
<cacheSettings cacheName="demoClusteredCache" connectionRetryInterval="300">
<expiration type="Absolute" duration="1" />
</cacheSettings>
</settings>
</ncContentOptimization>
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 threshold value will not be cached. |
cacheUriMapping |
Cache URL mapping, Default is true. |
enableTrace |
Enable/disable traces. |
cacheName |
Name of the Cache. |
connectionRetyInterval |
Retry Connection to Cache interval. Default is 300 seconds. |
Expiration |
Sets the expiration type which can either be Sliding , Absolute or None . And also expiration interval in minutes. |
Duration |
Sets expiration interval in minutes. |
Fetch View State Data
If the same cache is being used for 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.GetByTag(new Tag("NC_ASP.net_viewstate_data"));
The viewstate
of a particular session can easily be retrieved from 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