Use code to parse the Base64 value of ViewSate?

Source: Internet
Author: User
The value of ViewState is encoded in Base64, which is not encrypted by default and can be easily read.
The value of ViewState can be encrypted. First, make sure that EnableViewStatMac of Page is set to true, and then configure machineKey in Machine. Config.
MachineKey in Machine. Config by default: <! -- Validation = "[SHA1 | MD5 | 3DES]" -->
<MachineKey
ValidationKey = "AutoGenerate, IsolateApps"
DecryptionKey = "AutoGenerate, IsolateApps"
Validation = "SHA1"/>

You can modify the machineKey to use a certain encryption method. Note: encryption is completed by the Machine Layer, which consumes system resources.
I have not tested encryption ViewState.

You can use a browser to obtain the hidden content of ViewState. The following code can be used to parse private string Base2String (string message)
{
Byte [] by = System. Convert. FromBase64String (message );

String dest = System. Text. Encoding. ASCII. GetString ();
Return dest;

}
// If the value of ViewState is "dDw5NDA0MTAzOTY7dDxwPGw8cGFzczs + O2w8RmlzaDs + signature + ";
String source = "dDw5NDA0MTAzOTY7dDxwPGw8cGFzczs + O2w8RmlzaDs + signature + ";
Response. Write (Base2String (source ));

We can obtain: t <940410396; t

; L >;;>; L <_ctl0; check; _ ctl1; _ ctl2; _ ctl3; cb ;>>
Among them, cb refers to the dynamically generated CheckBox. A total of five checkboxes are dynamically generated. check refers to the dynamically generated 2nd CheckBox IDs, and other IDs are not specified.

If you complete the preceding operations in the Page background code, you need to override SavePageStateToPersistenceMedium (): protected override void SavePageStateToPersistenceMedium (object viewState)
{
// Call the methods of the base class to complete basic operations
Base. SavePageStateToPersistenceMedium (viewState );
// Obtain the Base64 value of ViewState
LosFormatter format = new LosFormatter ();
StringWriter writer = new StringWriter ();
Format. Serialize (writer, viewState );
String vsRaw = writer. ToString ();
Response. Write ("ViewState Raw:" + Server. HtmlEncode (vsRaw ));
// Parse content
Byte [] buffer = Convert. FromBase64String (vsRaw );
String vsText = Encoding. ASCII. GetString (buffer );
Response. Write ("ViewState Text:" + Server. HtmlEncode (vsText ));
}

Obtaining the value of ViewState can help you understand the purpose and function of ViewState. After all, StateBag in ViewState can store page-level variables and send them through PostBack.

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.