ASP. NET page encryption mechanism

Source: Internet
Author: User
ASP. NET encrypts viewstate.
Page. registerrequiresviewstateencryption
The method is to register the control as the control that requires view State encryption. If you want to develop a custom control for processing potential sensitive information, call the registerrequiresviewstateencryption method to register the control with the page and ensure that the view status information of the control is encrypted.
The registerrequiresviewstateencryption method must be Prerender Called in or before this phase. The following code is rewritten in the viewstatecontrol control. Onprerender And add the view encryption function. Code Section:
Protected override void onprerender (eventargs E)
{
This. Page. registerrequiresviewstateencryption ();
Base. onprerender (E );
}
Compile the control and run it again in the browser. You can see that the value of the hidden Domain View Control sent to the client is:

It becomes an encrypted hash code:

You can also specify the encryption mode of view status information, which is set by system enumeration viewstateencryptionmode. This enumeration can control whether to encrypt view status information. It has three enumeration items.

Enumeration member description
Auto: if the control requests Encryption by calling the registerrequiresviewstateencryption method, the view status information is encrypted; otherwise, the view status is not encrypted. This value is the default value of the page. viewstateencryptionmode attribute.
Always forcibly encrypts view status information, whether or not to call
Never does not encrypt view status even if the control requests encryption.
In addition to settings in the control, you can also configure the application in the configuration file. Program Level, or configure the page level in the page. When using a widget or page, make the following settings:

This. Page. viewstateencryptionmode = viewstateencryptionmode. Auto;
This. Page. registerrequiresviewstateencryption ();

after the preceding settings, the page framework automatically performs encryption and decryption. Add two more points to this function:
1. The encrypted view State will definitely affect the application performance. Therefore, exercise caution when using this function.
2. As long as any widget on the page needs to encrypt the view state, all view states on the page will also be encrypted. Currently, Asp. net has not implemented the encryption function of a control view on the needle page (the method of the page control page is called, whether in the control or on the page, registerrequiresviewstateencryption, and this method does not have any reload methods ).

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.