Asp. NET page to remove ViewState view state garbled

Source: Internet
Author: User
Tags object net object serialization serialization domain

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;
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.