Asp.net 2.0 viewstate principle (original)

Source: Internet
Author: User

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.

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.