
ViewState | 259
Page Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Example
The example obtains the user’s authentication status and name using the User
property and displays it in the browser:
Sub Page_Load( )
Message.Text = "Authenticated: " & _
User.Identity.IsAuthenticated & "<br/>"
Message.Text &= "User Name: " & User.Identity.Name
End Sub
Notes
For the IPrincipal object returned by the User property to be populated, some
form of authentication must be configured in either machine.config or web.config,
and, at a minimum, an authorization rule must be configured that excludes anon-
ymous users. If these conditions are not met, the IsAuthenticated property of the
IIdentity object will return
False and the Name property will return an empty
string.
ViewState
StateBag = Page.ViewState
The ViewState property returns an instance of the StateBag class containing state
information for server controls on the page. This StateBag instance can also store
arbitrary data that needs to be preserved across multiple requests for the same
page.
Parameter
StateBag
An object of type StateBag that contains the property values for server
controls on the page. This StateBag instance can also store arbitrary data that
needs to be preserved across multiple requests for the same page.
Example
The following code example sets the ForeColor property of the