How to encrypt View state for an individual page when it is requested

Software developer can encrypt an individual page only if a control specifically requests it using ViewStateEncryption-Mode property of the Page directive:

<%@Page ViewStateEncryptionMode=”Auto”>

The developer can set the same attribute in a configuration file:

<configuration xmlns =http://scemas.microsoft.com/.NetConfiguration/v2.0>
    <system.web>
        <pages viewStateEncryptionMode=”Auto”>
        …
    </system.web>
</configuration>

Note: Encryption imposes a performance penalty, because the web server will perform the encryption and decryption with each postback.  Don’t encrypt view state if you don’t need to do it.