Principle of ASP.net 2.0 viewstate

Source: Internet
Author: User

ViewState believe everyone will use, but viewstate in the end is what, and how many people know?

StateBag class that's not much to say.

In asp.net 2.0, there are three places to use StateBag.

1 Control._viewstate This is the viewState that everybody uses

2 Webcontrol.attrstate This is a store attribute.

3 Style.statebag is a store style.
.......
When saveallstate in page life cycle

Need mister into a Piar class, in calling this. Savepagestatetopersistencemedium (PAIR1), serializing it

Note: asp.net2.0 only implements Hiddenfieldpagestatepersister, and users can provide other forms of mechanism from overrides, or using ControlAdapter

Hiddenfieldpagestatepersister.save when Pair1 is serialized

When serialized,. NET provides three ways

1 Using a key

2. Using Mac

3 Do not use

Serialization first
This. Serialize (OutputStream, stategraph);

Outputstream.setlength (outputstream.position);
byte[] buf = Outputstream.getbuffer ();

int length = (int) outputstream.length;

Determines whether the current Page.requiresviewstateencryptioninternal property return value requires encryption
If Page.registerrequiresviewstateencryption is not invoked, the default is False
If the interface is set to RegisterRequiresViewStateEncryption and enableViewStateMac, encryption takes precedence over the 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)) Setting can use Mac
{
BUF = Machinekeysection.getencodeddata (buf, this. Getmackeymodifier (), 0, ref length);
}

Text = convert.tobase64string (buf, 0, length); Null of either

Speaking of this, a lot of people want to ask what is in the Pair1, I drew a picture, detailed description of the




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.