Open the source file of the ASPX page. By default, there is a segment <input type = "hidden" name = "_ viewstate" id = "_ viewstate" value = "/wepdwuk">.
The more controls the server, the more characters the value contains.
Value stores the status and value of the control and uses base64 encoding.
The method that does not display viewstate.
1. Set enableviewstate = "false" in the pages configuration node of the web. config file, or set it in the header of each ASPX page.
2. Delete the runat = "server" attribute in
4. Override the loadpagestatefrompersistencemedium () and savepagestatetopersistencemedium (object state) methods in the page class.
Protected losformatter;
Protected override object loadpagestatefrompersistencemedium ()
{
String key = request. rawurl + "_ viewstate ";
If (session [Key]! = NULL)
{
Memorystream stream = (memorystream) session [Key];
Stream. Seek (0, seekorigin. Begin );
Return losformatter. deserialize (Stream );
}
Return NULL;
}
Protected override void savepagestatetopersistencemedium (object state)
{
String key = request. rawurl + "_ viewstate ";
Memorystream stream = new memorystream ();
Losformatter. serialize (stream, State );
Stream. Flush ();
Session [Key] = stream;
}
5. Set <Form ID = "form1" runat = "server" enableviewstate = "false">.
This setting will still exist on the page. <input type = "hidden" name = "_ viewstate" id = "_ viewstate" value = "/wepdwuk">,
However, the value contains fewer characters.
The above content is post
For more information, see