ASP.NET View State Caching in NCache
NCache provides ASP.NET View State Caching as ASP.NET is widely used for high traffic web applications that need to handle millions of users and are deployed in load balanced web farms. ASP.NET View State is a powerful mechanism that stores pages, controls and custom values between multiple HTTP requests across client and the web server. View State is an ASP.NET method for persisting page and control states during post-backs. View State caching helps caching View State on web servers and send a much smaller payload to the user's browser containing only a unique ID for this View State. As a result, the page uses lesser bandwidth which improves performance and the ASP.NET application also scales much better.
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 following assembly reference in <compilation>
section of Web.config file:
Enterprise Edition:
<compilation defaultLanguage="c#" debug="true" targetFramework= "4.0">
<assemblies>
<add assembly="Alachisoft.NCache.Adapters, Version=x.x.0.0, Culture=neutral, PublicKeyToken=CFF5926ED6A53769">
</assemblies>
</compilation>
Professional and Open Source Editions:
<compilation defaultLanguage="c#" debug="true" targetFramework= "4.0">
<assemblies>
<add assembly="Alachisoft.NCache.Adapters, Version=x.x.x.x, Culture=neutral, PublicKeyToken=1448e8d1123e9096">
</assemblies>
</compilation>
Note
Replace Version=x.x.x.x with the actual NCache version that you have installed. For example, Version=4.8.0.0.
- 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" >
<cacheSettings cacheName="demoClusteredCache" connectionRetryInterval="300">
<expiration type="Absolute" duration="1" >
</cacheSettings>
</settings>
</ncContentOptimization>
For more details and features supporting View State like grouping View State in Sessions and limiting View State, refer to View State Caching in Programmers' Guide.