ViewState Chunking in asp.net

风格不统一 提交于 2019-12-18 02:43:35

问题


I keep on hearing this words "Viewstate Chunking". What is Viewstate Chunking?

And how it is working for ASP.NET pages?


回答1:


When the ViewState in your page becomes very large it can be a problem since some firewalls and proxies will prevent access to pages containing huge ViewState sizes. For this purpose ASP.NET introduces the ViewState Chunking mechanism. So ASP.NET enables splitting of the ViewState's single hidden field into several using the MaxPageStateFieldLength property in the web.config section.

When the MaxPageStateFieldLength property is set to a positive number, the view state sent to the client browser is broken into multiple hidden fields.

Setting the MaxPageStateFieldLength property to a negative number (the default) indicates that the view-state field should not be separated into chunks. Setting the MaxPageStateFieldLength to a small number may result in poor performance.

Sample ViewState before:

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"value="/wEPDwUKLTk2Njk3OTQxNg9kFgICAw9kFgICCQ88KwANAGQYAQUJR3Jp
ZFZpZXcxD2dk4sjERFfnDXV/hMFGAL10HQUnZbk=" />

Then set in web.config:

<pages maxPageStateFieldLength="40">

Sample ViewState After :

<input type="hidden" name="__VIEWSTATEFIELDCOUNT" id="__VIEWSTATEFIELDCOUNT"value="3" />
<input type="hidden" name="__VIEWSTATE"
id="__VIEWSTATE" value="/wEPDwUKLTk2Njk3OTQxNg9kFgICAw9kFgICCQ88" />
<input type="hidden" name="__VIEWSTATE1"
id="__VIEWSTATE1" value="KwANAGQYAQUJR3JpZFZpZXcxD2dk4sjERFfnDXV/" />
<input type="hidden" name="__VIEWSTATE2"
id="__VIEWSTATE2" value="hMFGAL10HQUnZbk=" /> 

hope it help you!




回答2:


From What's New in ASP.NET State Management - MSDN

If the amount of view-state data becomes too large, view-state chunking will automatically split the data into chunks and put the data into multiple hidden-form fields.

Why do we need Viewstate Chunking?

Here is an exerpt from ViewState Overivew - MSDN

Another important consideration is that if the amount of data in a hidden field becomes large, some proxies and firewalls will prevent access to the page that contains them. Because the maximum amount can vary with different firewall and proxy implementations, large hidden fields can cause sporadic problems. To help avoid this problem, if the amount of data stored in the ViewState property exceeds the value specified in the page's MaxPageStateFieldLength property, the page splits view state into multiple hidden fields to reduce the size of each individual field below the size that firewalls reject.



来源:https://stackoverflow.com/questions/10413986/viewstate-chunking-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!