where and how to use Page.RegisterRequiresViewStateEncryption()?
I would like to know how to register a control with viewState encryption.
The syntax of Page.RegisterRequiresViewStateEncryption()开发者_如何转开发
method does not indicate particular control other than the page object. Provide a sample code to answer this question would be very helpful.
RegisterRequiresViewStateEncryption() is to be used with the ViewStateEncryptionMode property of the Page
object. That property supports three values:
Always
: The page's view state will always be encrypted.Never
: The page's view state will never be encrypted, even ifRegisterRequiresViewStateEncryption()
is called by a control or the page itself.Auto
: The page's view state will be encrypted only ifRegisterRequiresViewStateEncryption()
is called by a control or the page itself.
So, if you call Page.RegisterRequiresViewStateEncryption()
from, say, one of your control's OnLoad()
method, or from the OnLoad()
method or Page_Load
event of your page, the view state will be encrypted, unless your page's ViewStateEncryptionMode
property is set to Never
.
The first link above contains a code sample that enables view state encryption on postback if the end user chose to retrieve sensitive information.
精彩评论