Remove viewstate from Asp.net

Source: Internet
Author: User

When so many pieces of things are generated, this piece of things has no benefit to Seo at all. What I want to do is remove it, but one thing is to remove it, but it cannot change its original controls and content. Let's look at this section.Code:
When so many pieces of things are generated, this piece of things has no benefit to Seo at all. What I want to do is remove it, but one thing is to remove it, but it cannot change its original controls and content, for example, it cannot be used. So all I have to do is save the data in another way. This is a piece of base64-encoded data, not encrypted. I'm curious about what I put here. Next I started to crack this code. The Code is as follows:

Copy codeThe Code is as follows:
Viewstate is saved in the page. savepagestatetopersistencemedium method. When sending back, the viewstate is restored in the page. loadpagestatefrompersistancemedium method. This is an article I am reading the translation of "wooye Hu ".ArticleWe can save it to the session. The Code is as follows:

Copy codeThe Code is as follows:

Protected losformatter = new losformatter ();
Protected override object loadpagestatefrompersistencemedium ()
{
String key = request. rawurl + "_ viewstate ";
If (session [Key]! = NULL)
{
System. Io. memorystream stream = (system. Io. memorystream) session [Key];
Stream. Seek (0, system. Io. seekorigin. Begin );
Return losformatter. deserialize (Stream );
}
Return NULL;
}
Protected override void savepagestatetopersistencemedium (Object viewstate)
{
String key = request. rawurl + "_ viewstate ";
System. Io. memorystream stream = new system. Io. memorystream ();
Losformatter. serialize (stream, viewstate );
Stream. Flush ();
Session [Key] = stream;
}

Now let's look at the current viewstate:

Copy codeThe Code is as follows:

<Input type = "hidden" name = "_ eventtarget" id = "_ eventtarget" value = ""/>
<Input type = "hidden" name = "_ eventargument" id = "_ eventargument" value = ""/>
<Input type = "hidden" name = "_ viewstate" id = "_ viewstate" value = ""/>

In this step, we implement the functions we need to use to remove viewstate and keep the original page in use.

 

From: http://www.itxuexi.com/tech/wangluobiancheng/dotnet/384501255272077.html

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.