ASP.NET is widely used for high-traffic web applications that handle millions of users simultaneously. Organizations deploy these applications across load-balanced web farms. One important aspect of ASP.NET is the View State, a mechanism that stores pages, controls, and custom values between multiple HTTP requests between the client and the web server. However, leveraging View State effectively, as intended, can impact performance and bandwidth.
Key Takeaways
Eliminate Payload Bloat: Standard ASP.NET View State stores page data in a hidden Base64 string that can exceed 100KB, slowing down response times; NCache replaces this with a tiny 40-byte GUID.
Reduce Cloud Egress Costs: By keeping heavy View State data on the server and only sending a token to the browser, you significantly lower bandwidth usage and associated costs in Azure or AWS deployments.
Enhance Web Farm Scalability: In load-balanced environments, a distributed cache like NCache ensures View State is synchronized across all server nodes, preventing “View State MAC validation” errors.
Improve Application Security: Sensitive form data is stored securely in the server-side cache rather than being exposed in the client’s browser HTML.
Low-Code Implementation: Optimizing View State with NCache requires zero logic changes to your application. It only requires minor configurations in the web.config and app.browser files.
What is ASP.NET View State?
This powerful feature tracks user input and selections on a web page, even after a reload or refresh. It allows the web application to retain user input and selections without requiring server-side sessions. View State values are stored in a hidden field on the page and encoded as a Base64 string. It looks like this:
|
1 2 3 4 |
<input id="__VIEWSTATE" type="hidden" name="__VIEWSTATE" value="/wEPDwUJNzg0MDMxMDA1D2QWAmYPZBYCZg9kFgQCAQ9kFgICBQ9kFgJmD2QWAgIBD xYCHhNQcm2aW91c0NvbnRyb2xNb2RlCymIAU1pY3Jvc29mdC5TaGFyZVBvaW50Lld lYkNvbnRyb2xzLlNQQ29udHJbE1vZDA1XzRlMjJfODM3Y19kOWQ1ZTc2YmY1M2IPD 2…==" /> |
Challenges with ASP.NET View State
While View State is incredibly useful, it can become quite large, especially in applications featuring complex controls like grid views. The increased size makes HTTP requests and responses larger, slowing down the application’s response time due to Base64 serialization overhead and increased HTTP payload size.
Another downside is the increased bandwidth usage, which impacts network latency and significantly raises egress costs in cloud deployments like Azure or AWS. For instance, if each HTTP request adds 60-100 KB of View State data, multiplying this by the total number of transactions quickly escalates costs. Lastly, sending sensitive data as part of the View State poses security risks, making encryption necessary—a process that can be costly in terms of performance.
Why Cache ASP.NET View State?
To mitigate these challenges, caching ASP.NET View State on the web server and assigning a GUID as its key can be highly effective. The server sends this GUID to the browser in a hidden field, and the browser returns it with the next HTTP request. The server then uses the GUID to fetch the corresponding View State from the cache. This approach reduces the payload sent to the browser, significantly improving response times and drastically lowering bandwidth costs.
The following comparison highlights how moving the View State from the client-side to a distributed cache like NCache fundamentally transforms your application’s resource profile:
| Feature | Standard ASP.NET View State | Cached View State with NCache |
|---|---|---|
| Client-Side Payload | Large (often 100KB+) | Minimal (approx. 40 bytes) |
| Bandwidth Consumption | High (transferred every request) | Very Low (GUID exchange only) |
| Security Risk | High (exposed in hidden field) | Low (data stays in secure cache) |
| Server Performance | Lower (due to heavy serialization) | Optimized (fast in-memory retrieval) |
Configuring NCache for ASP.NET View State Caching
If your ASP.NET application runs in a load-balanced web farm, you must use a distributed cache. A stand-alone cache like the ASP.NET Cache won’t work. To this end, NCache is an enterprise-level distributed cache that provides an ASP.NET View State caching module. Implementing it requires minimal code changes—just a small modification to your ASP.NET web.config file. Follow the steps below to set it up.
- Create an app.browser file in your ASP.NET application under the directory App_browsers. Add your page adapters to the app.browser file as shown below.
12345<browser refID="Default"><controlAdapters><adapter controlType="System.Web.UI.Page"adapterType="Alachisoft.NCache.Adapters.PageAdapter"/></controlAdapters></browser> - Then add the following assembly reference in the compilation section of the web.config file.
1234567<compilation defaultLanguage="C#" debug="true"><assemblies><add assembly="Alachisoft.NCache.Adapters,Version=1.0.0.0,Culture=neutral,PublicKeyToken=cff5926ed6a53769"/></assemblies></compilation> - Register your config section in the web.config file.
1234567<configSections><sectionGroup name="ncContentOptimization"><section name="settings"type="Alachisoft.NCache.ContentOptimization.Configurations.ContentSettings"allowLocation="true" allowDefinition="Everywhere"/></sectionGroup></configSections> - Specify settings for your config section in the web.config file (that was registered above).
12345678910<ncContentOptimization><settings enableMinification="true"enableViewstateCaching="true"groupedViewStateWithSessions="true"viewstateThreshold="0"enableTrace="true"><cacheSettings cacheName="mycache"><expiration type="Sliding" duration="300"/></cacheSettings></settings></ncContentOptimization> - In the end, register the HTTP handler in the HttpHandlers section of web.config as follows.
12345<add verb="GET,HEAD" path="NCResource.axd"validate="false"type="Alachisoft.NCache.Adapters.ContentOptimization.ResourceHandler,Alachisoft.NCache.Adapters, Version=1.0.0.0,Culture=neutral,PublicKeyToken=cff5926ed6a53769"/>
After configuring NCache, you can see the View State tag in your application as shown below.
|
1 2 3 4 5 6 |
<input type="hidden" name="__NCPVIEWSTATE" id="__NCPVIEWSTATE" value="vs:cf8c8d3927ad4c1a84da7f891bb89185"/> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value=""/> |
Notice that another hidden tag is added with ASP.NET View State. This new tag holds a unique key that links to the View State stored in your distributed cache. When the application server needs to retrieve the View State, it can quickly access it from the cache, significantly boosting performance.
Conclusion
By caching your ASP.NET View State with NCache, you can achieve remarkable improvements in your application response times while drastically reducing bandwidth costs. This simple yet effective solution significantly enhances the overall performance of your ASP.NET applications, making them more efficient and resource-effective. Explore these benefits by trying out the NCache ASP.NET View State module for yourself!
Frequently Asked Questions (FAQ)
Q: Why is a distributed cache required instead of a local ASP.NET cache?
A: Standard ASP.NET caching is local to a single server. In a load-balanced web farm, if a postback request lands on a different server than the original request, the local cache won’t have the View State. NCache provides a distributed environment where all servers in the farm share the same View State data.
Q: What is the purpose of the viewstateThreshold setting?
A: The viewstateThreshold (in KB) allows you to set a minimum size limit for caching. If a page’s View State is smaller than this threshold, it remains on the client-side as usual. This ensures that you only use cache resources for “heavy” View States that actually cause performance bottlenecks.
Q: Does caching View State require any changes to my existing .NET code?
A: No. The integration is handled at the provider level. By registering the Alachisoft.NCache.Adapters in your web.config and app.browser files, NCache automatically intercepts the View State lifecycle without you needing to rewrite your page logic.
Q: How does the browser know which View State to retrieve from the cache?
A: NCache replaces the massive Base64 string in the __VIEWSTATE hidden field with a unique, lightweight GUID. On a postback, the browser sends this GUID back to the server, which NCache uses as a key to instantly fetch the original data from the cluster.
Q: Can I link View State expiration with a user’s session?
A: Yes. By setting groupedViewStateWithSessions=”true” in your configuration, NCache can automatically clear a user’s cached View States when their ASP.NET Session expires, helping to optimize memory usage in the cache cluster.







You can use NCache for Azure for storing ASP.NET Session State for Microsoft Azure ASP.NET applications. Here is a blog that explains Microsoft Azure Session Storage options and why NCache for Azure is best among all available options in Microsoft Azure.
https://20.200.20.123:86/storing-asp-net-session-state-in-a-microsoft-azure-distributed-cache/
Anyone successfully using Windows Azure Caching (Preview) to handle session state?