First statement of this 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 (had been deleted!) )
Saves all view state information and control state information for the page.
The authors have encountered this need in early-stage projects: Based on SEO technology development, when there is no contact with the MVC framework of the Razor engine, So only use the ASP.net engine, if you use the server-side control of the ASP.net engine, then in the ASP.net page will generate __viewstate hidden fields , __viewstate hidden domain generated " garbled " is extremely unfriendly to the Web crawler!!
" garbled " is as follows:
Here we discuss some of the following scenarios.
Programme I:
By removing the runat= "server" attribute of the form's label, you can not generate __viewstate hidden fields, but in some cases the server-side controls are not working properly, so it is not perfect when you need to use server-side controls.
Programme II:
The EnableViewState property of the control to the server is set to False, at which point we find that the viewstate of the Web page has obvious code reduction, but there is still view state ...
Programme III:
Some programs need to be understood. NET, such as System.Web.dll .
The System.Web.dll encapsulates the LosFormatter class.
A description of this class on MSDN is the serialization of view state for a Web forms page.
At this point we need the Serialize method encapsulated in the LosFormatter class, which functions as follows: Converts an object in a finite object serialization (LOS) format to a view state value and places the result in a System.IO.Stream object.
Remove "garbled" code as follows:
///Removal viewstate garbled code as follows:
///
protected LosFormatter losformatter = new LosFormatter ();
///Serializes all view state information and control state information.
///
/// Object in which to store view state information protected
erride void Savepagestatetopersistencemedium (object viewState)
{
string val = request.url + ' __viewstate '; c11/> System.IO.MemoryStream stream = new System.IO.MemoryStream ();
Losformatter.serialize (stream, viewState);
Stream. Flush ();
Session[val] = stream;
}