Step 1: Add below web config code to add Encryption in ViewState data.
- <pages controlRenderingCompatibilityVersion="3.5" enableEventValidation="false"
- clientIDMode="AutoID" viewStateEncryptionMode="Always">
Now, your viewstate data is encrypted and key is macid
But If you want to add more security then you can add customize key for encryption
To apply this assign your key to "ViewStateUserKey" which is page property.
- protected override void OnInit(EventArgs e)
- {
- ViewStateUserKey = Session.SessionID;
- }
And please assign it in oninit method because view state should not load before assigned key.
Above two are best ways to prevent your viewstate data