Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [102]

By Root 5433 0

IsCrossPagePostBack

Indicates whether the page is being loaded in response to a postback made from within another page.

IsPostBack

Indicates whether the page is being loaded in response to a client postback or whether it is being loaded for the first time.

IsValid

Indicates whether page validation succeeded.

Master

Instance of the MasterPage class; represents the master page that determines the appearance of the current page.

MasterPageFile

Gets and sets the master file for the current page.

NamingContainer

Returns null.

Page

Returns the current Page object.

PageAdapter

Returns the adapter object for the current Page object.

Parent

Returns null.

PreviousPage

Returns the reference to the caller page in case of a cross-page postback.

TemplateSourceDirectory

Gets the virtual directory of the page.

Validators

Returns the collection of all validation controls contained in the page.

ViewStateUserKey

String property that represents a user-specific identifier used to hash the view-state contents. This trick is a line of defense against one-click attacks.

In the context of an ASP.NET application, the Page object is the root of the hierarchy. For this reason, inherited properties such as NamingContainer and Parent always return null. The Page property, on the other hand, returns an instance of the same object (this in C# and Me in Visual Basic .NET).

The ViewStateUserKey property deserves a special mention. A common use for the user key is to stuff user-specific information that is then used to hash the contents of the view state along with other information. A typical value for the ViewStateUserKey property is the name of the authenticated user or the user’s session ID. This contrivance reinforces the security level for the view state information and further lowers the likelihood of attacks. If you employ a user-specific key, an attacker can’t construct a valid view state for your user account unless the attacker can also authenticate as you. With this configuration, you have another barrier against one-click attacks. This technique, though, might not be effective for Web sites that allow anonymous access, unless you have some other unique tracking device running.

Note that if you plan to set the ViewStateUserKey property, you must do that during the Page_Init event. If you attempt to do it later (for example, when Page_Load fires), an exception will be thrown.

Context Properties


Table 5-10 lists properties that represent visual and nonvisual attributes of the page, such as the URL’s query string, the client target, the title, and the applied style sheet.

Table 5-10. Page-Specific Properties of the Page Class

Property

Description

ClientID

Always returns the empty string.

ClientIDMode

Determines the algorithm to use to generate the ID of HTML elements being output as part of a control’s markup. This property requires ASP.NET 4.

ClientQueryString

Gets the query string portion of the requested URL.

ClientTarget

Set to the empty string by default; allows you to specify the type of browser the HTML should comply with. Setting this property disables automatic detection of browser capabilities.

EnableViewState

Indicates whether the page has to manage view-state data. You can also enable or disable the view-state feature through the EnableViewState attribute of the @Page directive.

EnableViewStateMac

Indicates whether ASP.NET should calculate a machine-specific authentication code and append it to the page view state.

EnableTheming

Indicates whether the page supports themes.

ID

Always returns the empty string.

MetaDescription

Gets and sets the content of the description meta tag. This property requires ASP.NET 4.

MetaKeywords

Gets and sets the content of the keywords meta tag. This property requires ASP.NET 4.

MaintainScrollPositionOnPostback

Indicates whether to return the user to the same position in the client browser after postback.

SmartNavigation

Indicates whether smart navigation is enabled. Smart navigation exploits

Return Main Page Previous Page Next Page

®Online Book Reader