Viewstate is always used by everyone. What is viewstate and how many people know it?
I don't need to say much about the statebag class.
In Asp.net 2.0, statebag is used in the following types:
1 control. _ viewstate this is the viewstate used by everyone.
2 webcontrol. attrstate: This stores attribute.
3 style. statebag stores styles.
4. cssstylecollection. statebag
.......
When the page is saveallstate In the lifecycle
Must be a PIAR class,
Serialize this. savepagestatetopersistencemedium (pair1 );
Note: Asp. net2.0 only implements hiddenfieldpagestatepersister. You can rewrite it, or use controladapter to provide other forms of inbound mechanisms.
Hiddenfieldpagestatepersister. Save will be serialized through pair1
During serialization,. NET provides three methods
1. Use the key
2. Use MAC
3 not used
This. serialize (outputstream, stategraph );
Outputstream. setlength (outputstream. position );
Byte [] Buf = outputstream. getbuffer ();
Int length = (INT) outputstream. length;
Serialization first
// Determine whether encryption is required for the returned value of the current page. requiresviewstateencryptioninternal attribute,
// If page. registerrequiresviewstateencryption is not called, the default value is false.
// If registerrequiresviewstateencryption and enableviewstatemac are set on the interface, encryption takes precedence over Mac.
If (this. _ page! = NULL) & this. _ page. requiresviewstateencryptioninternal) // Encryption
{
Buf = machinekeysection. encryptordecryptdata (true, Buf, this. getmackeymodifier (), 0, length );
Length = Buf. length;
}
Else if (this. _ page! = NULL) & this. _ page. enableviewstatemac) | (this. _ mackeybytes! = NULL) // you can use Mac
{
Buf = machinekeysection. getencodeddata (BUF, this. getmackeymodifier (), 0, ref length );
}
TEXT = convert. tobase64string (BUF, 0, length); // null of either
When talking about this, many people want to ask what is put in pair1. I drew a picture and explained it in detail.