First of all, the following article: This article was published in 2014-10-11, the original author and Copyright: Koalaapi (or I), the original link: http://www.cnblogs.com/KoalaAPI/p/4018727.html (has been deleted!) )
Saves all view state information and control state information for the page.
The author had encountered such a need in an early engagement project: Based on SEO technology, when the Razor engine was not exposed to the MVC framework, So you can only use the ASP. If you use the ASP. NET engine server-side control, the __viewstate hidden field is generated in the ASP. __viewstate The hidden field produces a " garbled " The web crawler is extremely unfriendly!!
" garbled " is as follows:
1 <Divclass= "Aspnethidden">2 <inputtype= "hidden"name= "__eventvalidation"ID= "__eventvalidation"value= "/wedaaevvxd1oyelevemr0vhcmyp7lzjrictidqhsmkvwuzulg+r/e5r2ibu8/ usjbp6bve2c4is0s7hmhxw1jonuyef5swtlaaw1o1yuxny4tbozokqfv7txcrdfrrz4sk+ Amqj1hxkqp47r3pb8oaxkfqkk9svcu9vqcv7t6ajmdaydjyd0irvsrgxq8lavspmz9m= " />3 </Div>
View Code
Then all the problems come, in the development of commercial projects we need to __viewstate hidden domain generated "garbled" removed.
Here we discuss the following scenarios.
Programme one:
Without the runat= "server" attribute of the form's label, you can not generate __viewstate hidden fields, but in some cases server-side controls are not working properly, so it is not perfect when you need to use server-side controls.
Scenario Two:
The EnableViewState property of the correct server control is set to false, when we find that the viewstate of the Web page is significantly reduced, but there is still a view state ...
Programme III:
Need to know about these options. NET of some base classes, such as System.Web.dll .
The System.Web.dll encapsulates the LosFormatter class.
The description of this class on MSDN is: The view state of the serialized Web forms page.
At this point we need to encapsulate the Serialize method in the LosFormatter class, which is described as follows: Converts an object in the finite object serialization (LOS) format to a view state value and places the result in the System.IO.Stream object.
Remove the "garbled" code as follows:
/// <summary> ///The ViewState garbled code is removed as follows:/// </summary> protectedLosFormatter LosFormatter =NewLosFormatter (); /// <summary> ///serializes all of the view state information and control state information. /// </summary> /// <param name= "ViewState" >Object in which to store the view state information</param> protected Override voidSavepagestatetopersistencemedium (ObjectviewState) { stringval = Request.url +"__viewstate"; System.IO.MemoryStream Stream=NewSystem.IO.MemoryStream (); Losformatter.serialize (stream, viewState); Stream. Flush (); Session[val]=stream; }
View Code
Asp. NET page removal of ViewState view state garbled