ASP.NET View State Caching in Microsoft Azure for Better Performance

ASP.NET View State is a client side state management mechanism, which is used to save page and control values. ASP.NET View State is a hidden field on the page as an encoded Base64 string. It is sent to client as part of every response and is returned to the server by the client as part of a post back.

XHTML

1

2

3

4

5

6

7

8

9

<input id="__VIEWSTATE"type="hidden"

name="__VIEWSTATE"value="wEPDwUJNzg0MDMxMDA1D2QWAmYPZBYCZg9kFgQ

CQ9kFgICBQ9kFgJmD2QWAgIBDxYCHhNQcm2aW91c0NvbnRyb2xNb2RlCymIAU1pY3

Jvc29mdC5TaGFyZVBvaW50LldlYkNvbnRyb2xzLlNQQ29udHJbE1vZGUsIE1pY3Jv

29mdC5TaGFyZVBvaW50LCBWZXJzaW9uPTEyLjAuMC4wLCBDdWx0dXJlPW5ldXRyWw

sIFB1YmxpY0tleVRva2VuPTcxZTliY2UxMTFlOTQyOWMBZAIDD2QWDgIBD2QWBgUm

Z19lMzI3YTQwMF83ZDA1XzRlMjJfODM3Y19kOWQ1ZTc2YmY1M2IPD2RkZAUmZ18yN

DQ3NmI4YV8xY2FlXzRmYTVfOTkxNl8xYjIyZGYwNmMzZTQPZBYCZg8PZBYCHgVjbG

DQWBgUmZ19lMzI3YTQwMF83ZDA1XzRlMjJfODM3Y19kOWQ1ZTc2YmY1M2IPD2...."/>

Problems with ASP.NET View State in Microsoft Azure

ASP.NET View State is a very important feature for applications deployed as web/worker roles in Microsoft Azure Cache. But, View state comes with some issues that you need to understand and resolve in order to take full benefit from it.

First of all, ASP.NET View State becomes very large especially when your Microsoft Azure ASP.NET application has a lot of heavy controls on its pages. This results in heavy view state payload which travels back and forth between browser and your application on each request. Heavy view state payload slows down performance and also results in extra bandwidth consumption especially when an average ASP.NET View State ends up in 100’s of kilobytes and when millions of such requests are processed within your Microsoft Azure application.

ASP.NET View State is also a security risk when sending confidential data as part of view state to client. This data is vulnerable to attacks and can be tampered with by an attacker, which is a serious security threat.

Solution to ASP.NET View State Problems

You can resolve ASP.NET View State issues in Microsoft Azure applications by storing the actual ASP.NET View State on the server side in a distributed cache and never send it back to browser along with request payload.

NCache for Azure is an extremely fast and scalable distributed cache for Microsoft Azure. It allows you to store actual ASP.NET View State in Distributed Cache on server side and instead send a small token as view state to the client in a request payload. This dramatically reduces the request payload size. View State token is then used on the server side to find the right ASP.NET View State in NCache for Azure Distributed Cache on post backs. A smaller payload resolves issues related to performance and bandwidth utilization because you are not dealing with huge view state anymore on each request in your Microsoft Azure Application. Moreover, View State stored on the server side in NCache for Azure distributed cache is never exposed to clients so it addresses the above mentioned security concerns.

Here is an example of a token being used in place of ASP.NET View State with NCache for Azure ASP.NET View State provider:

1

2

<input type="hidden"name="__VIEWSTATE"id="__VIEWSTATE"

value="cf8c8d3927ad4c1a84dsadfgsdsfdsda7f891bb89185"/>

Using NCache for Azure ASP.NET View State Caching

Step 1: Create an app.browser file in App_browsers directory. Plug in page adapters in the app.browser file as follows:

File: App_browsersapp.browser

1

2

3

4

5

6

<browser refID="Default">

<controlAdapters>

<adapter controlType="System.Web.UI.Page"

adapterType="Alachisoft.NCache.Adapters.PageAdapter"/>

</controlAdapters>

</browser>

Step 2: Add the following assembly reference in compilation section of web.config file.

NCache for Azure provides a no code change option for your Microsoft Azure applications to store ASP.NET View State on the server side in a Distributed Cache. NCache for Azure ASP.NET View State provider optimizes performance by reducing request payload and bandwidth consumption while addressing security issues related to client side View State.

By Default, NCache keeps all ViewStates indefinitely in the cache regardless how late the post back is issued. Therefore all view state requests will be handled by the cache.

On the other hand, you can also associate time base expirations (Absolute or sliding) to ViewState and set the value high enough to avoid cache misses even after a long pots back time.

You can also group ViewState with NCache Sessions. This way when a user session is removed from cache, all related ViewStates are automatically removed. This helps to avoid extra memory load on the cache providing you the best performance.

I have configured all steps that you described in the article, but, the view state string didnt change and didnt get smaller size, the main idea is ncache replace the string with his own string and then, ncache in the execution time will pass the original string to asp.net, i’m wrong?

please let me know, how can i get more information or if will be posible to get remote assistance ?

As far as view state not caching, there must be something wrong with your configuration specific to your environment. We will shortly send an email to you at your registered email address to coordinate and further help you out.