Class PageBase
BasePage for EPiServer templates. Supports encoding settings and language translation.
Inheritance
Namespace: EPiServer
Assembly: EPiServer.dll
Version: 8.11.0Syntax
public abstract class PageBase : Page, IPageSource, ICurrentPage, IContentSource, ISupportsScriptManager
Remarks
This class inherits from System.Web.UI.Page, which has the core functionality for setting up and rendering a standard Web form (.aspx file.) The PageBase class extends the functionality of the Page class with EPiServer-specific features as access to configuration settings (Configuration property), user information (CurrentUser property) and information about the current EPiServer page (CurrentPage property.)
The PageBase class is an abstract class, meaning it cannot be instantiated. This class is the base class of all template classes in EPiServer. TemplatePage is the most used class as base for Web forms.PageBase also implements the IPageSource interface, which enables you to retrieve other EPiServer pages easily.
note
If you use anything apart from templates that inherit from PageBase to create EPiServer page types, no dynamic content will be presented on the Web page.
Constructors
PageBase(Int32)
Initializes a new instance of the PageBase class.
Declaration
public PageBase(int options)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | options | The page options to enable. |
Remarks
The options parameter is a bitmap constructed from the OptionFlag of Page plugin classes from the EPiServer.Web.PageExtensions namespace.
PageBase(Int32, Int32)
Initializes a new instance of the PageBase class.
Declaration
public PageBase(int enable, int disable)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | enable | The page options to enable. |
System.Int32 | disable | The page options to disable. |
Remarks
The disable bitmap will override enabled options in case of conflicting options.
Properties
ContextMenu
Gets or sets the context menu for this page.
Declaration
[Obsolete("Rightclick menu is not used on pages anymore")]
public ContextMenu ContextMenu { get; set; }
Property Value
Type | Description |
---|---|
ContextMenu | The context menu. |
Remarks
To enable the context menu you should make sure that ContextMenu.OptionFlag (in namespace EPiServer.Web.PageExtensions) is set for the PageBase constructor parameter.
CurrentPage
Get page data for current page.
Declaration
public virtual PageData CurrentPage { get; set; }
Property Value
Type | Description |
---|---|
PageData | A PageData object, null if failure. |
Remarks
A little caution is necessary when using CurrentPage in the HTML part of Web forms, as CurrentPage is implemented from IPageSource and UserControlBase also implements IPageSource. This means that CurrentPage will have different meanings in the same Web form depending on whether it's used outside any included EPiServer Web custom control in general and outside any templated EPiServer Web custom control in particular.
Examples
The following code example demonstrates the usage of both CurrentPage and Configuration. The example is used in EPiServer's sample Web site to send e-mail. Configuration is used to initalize the mail server and also, together with CurrentPage, to send information to the recipient of the e-mail.
The following example demonstrates the usage of CurrentPage on a page template file, outside of any included controls.
The following example demonstrates the usage of CurrentPage on a page template file, inside ContentFramework and Content controls.
The following example demonstrates the usage of CurrentPage inside an EPiServer templated control.
The following code example demonstrates the usage of CurrentPage and IsValue. CurrentPage is used to read the content of two properties; NewsCount and MainImage. To safeguard the property access, the presence and possible contents of both properties are first tested using the IsValue method.
CurrentPageHandler
Gets or sets the current page handler.
Declaration
public ICurrentPage CurrentPageHandler { get; set; }
Property Value
Type | Description |
---|---|
ICurrentPage | The current page handler. |
Remarks
The page handler is used to retrieve the current page. By assignig your own implementation to this property you can take control over the process of retrieving the current page.
CurrentPageLink
Get the reference to the current page.
Declaration
public virtual PageReference CurrentPageLink { get; set; }
Property Value
Type | Description |
---|---|
PageReference | A PageReference to the current page. |
Remarks
Parses the query string / form parameters to get the page reference.
CurrentPageLink has no place inside templated controls, since the Container property is of the type PageTemplateContainer, which doesn't implement CurrentPageLink.Examples
The following code example demonstrates the usage of CurrentPageLink to retrieve the PageData object.
EditHints
Gets the list containing the names of properties that have been registered for full refresh.
Declaration
public IList<string> EditHints { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IList<System.String> |
Remarks
This list will be read by the FullRefreshPropertiesMetaData and output as a comma separated list that that will be collected by the edit interface client.
IsDefaultPageLink
Determine if the current page request was done without an "id=..." parameter.
Declaration
public bool IsDefaultPageLink { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
The system will handle a missing id parameter by using the pageStartId value from EPiServer.Configuration.
IsDesignMode
Gets a value indicating whether this instance is design mode.
Declaration
protected bool IsDesignMode { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsNewPage
Gets a value indicating whether this instance is creating a new page in EPiServer.
Declaration
[Obsolete("Save handler is no longer support, use regular IContentRepository API's to save content")]
public bool IsNewPage { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
The property will throw a System.NullReferenceException if SavePageHandler has not been defined.
LocalizationService
The localizationService used by the various Translate methods on PageBase.
Declaration
protected virtual LocalizationService LocalizationService { get; set; }
Property Value
Type | Description |
---|---|
LocalizationService |
Remarks
Will return the static property Current if not set.
Locate
Gets the object used to resolve services part of the public API.
Declaration
public ServiceLocationHelper Locate { get; }
Property Value
Type | Description |
---|---|
ServiceLocationHelper |
NewPageParent
Gets the page that a newly created page will be placed below.
Declaration
[Obsolete("Save handler is no longer support, use regular IContentRepository API's to save content")]
public PageReference NewPageParent { get; }
Property Value
Type | Description |
---|---|
PageReference |
Options
Gets the page extension options, which is a bitmap constructed from the OptionFlag of Page plugin classes from the EPiServer.Web.PageExtensions namespace.
Declaration
public int Options { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
PageTranslation
Gets or sets the page translation object.
Declaration
public PageTranslation PageTranslation { get; set; }
Property Value
Type | Description |
---|---|
PageTranslation | The page translation. |
SavePageHandler
Gets or sets the save page handler.
Declaration
[Obsolete("Save handler is no longer supported, use regular IContentRepository API's to save content")]
public ISavePage SavePageHandler { get; set; }
Property Value
Type | Description |
---|---|
ISavePage | The save page handler. |
Remarks
The save page handler is responsible for saving the current page. You may create your own implementation of ISavePage if you have very specific needs, but this is not recommended as it is a very complex task.
ScriptManager
Gets the script manager.
Declaration
public ScriptManager ScriptManager { get; }
Property Value
Type | Description |
---|---|
ScriptManager | The script manager. |
Methods
AccessDenied()
The method that is invoked when the current users access rights are not suffcient for the operation that he tries to perform.
Declaration
public virtual void AccessDenied()
Remarks
This method will perform different functions depending on the authentication method in use. If forms authentication is used, then it will redirect the user to the login page as defined in web.config. If windows authentication is used, an Access Denied header (http status 401) will be sent to the client.
Examples
The following code example demonstrates the usage of AccessDenied to deny access to a user that is not logged on. The example is taken from the Web user control LoginStatus.ascx, which is delivered with EPiServer. It must be understood that the click event for ASP.NET Server control Login has been linked to the function Login_Click, so that when the user clicks the Login button, this function is executed. Note that the call to AccessDenied does not necessarily mean that the user is denied access - it can also be used to present the user with a login dialog. This happens in Web user control QuickBar.ascx.
BuildUrlWithPageReference(String, PageReference)
Helper method to construct a URL with a page reference parameter
Declaration
public string BuildUrlWithPageReference(string url, PageReference pageLink)
Parameters
Type | Name | Description |
---|---|---|
System.String | url | The original URL |
PageReference | pageLink | Page that should be referenced by the URL |
Returns
Type | Description |
---|---|
System.String | A new URL |
Remarks
This method is primarily intended to be used with a URL read from the PageURL property of a PageData class. In some special cases you may need to retarget the URL to another page or another version of the same page.
CheckAccess()
Verify that access control requirements are met for the current web request.
Declaration
public void CheckAccess()
Remarks
This method is called as part of the PageBase.OnInit method. It determines the current user's access level and compares it to the current page. If the user does not have sufficient access, the PageBase.AccessDenied method will be called.
note
Will trigger an AccessDenied if the access requirements are not met.
Get<T>(ContentReference)
Shortcut to retrieve an IContent object from the currently configured IContentRepository specified by the ContentReference parameter.
Declaration
public T Get<T>(ContentReference contentLink)
where T : IContentData
Parameters
Type | Name | Description |
---|---|---|
ContentReference | contentLink | Reference to the content to retrieve. |
Returns
Type | Description |
---|---|
T | The IContent object requested. |
Type Parameters
Name | Description |
---|---|
T | The type of the content object to be retrieved. |
See Also
GetChildren(PageReference)
Retrieves a PageData listing based on supplied PageReference argument (from IPageSource).
Declaration
public virtual PageDataCollection GetChildren(PageReference pageLink)
Parameters
Type | Name | Description |
---|---|---|
PageReference | pageLink |
Returns
Type | Description |
---|---|
PageDataCollection |
Remarks
The IPageSource interface is implemented by many classes, such as PageBase (and its descendants), DataFactory, PageControlBase. You typically use the members of this interface to get information about the current page (the CurrentPage property) or use either the GetPage or GetChildren methods to retrieve page data.
IPageSource was created as an interface due to the fact that the GetPage and GetChildren methods normally have the same implementation independently of the class that implements IPageSource. The CurrentPage property has different meanings for different implementations. As an example, CurrentPage on the PageBase class refers to the currently loaded page (based on the ID in the query string).
note
Note: As IPageSource is an interface, it doesn't implement any of its own attributes or methods itself. This means that you must be aware of which class implementing IPageSource that you're dealing with. For example, PageBase.CurrentPage returns a PageData object for the current page, the same for UserControlBase. However, in a templated control such as EPiServer.Web.WebControls.PageList, CurrentPage instead means the current page in the iteration.
Examples
The following code example demonstrates a specialized implementation of IPageSource to set custom access level restrictions to the pages returned.
GetChildren<T>(ContentReference)
Shortcut to retrieve an IContent listing from the currently configured IContentRepository.
Declaration
public IEnumerable<T> GetChildren<T>(ContentReference contentLink)
where T : IContentData
Parameters
Type | Name | Description |
---|---|---|
ContentReference | contentLink | Reference to parent content whose children to retrieve. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> | Returns a collection of IContent directly below the content referenced by the ContentReference parameter. |
Type Parameters
Name | Description |
---|---|
T | The type of the content objects to be retrieved. |
See Also
GetPage(PageReference)
Retrieves a PageData object based on supplied PageReference argument (from IPageSource).
Declaration
public virtual PageData GetPage(PageReference pageLink)
Parameters
Type | Name | Description |
---|---|---|
PageReference | pageLink |
Returns
Type | Description |
---|---|
PageData | Returns the PageData object for the specified PageReference argument. |
Examples
The following code example demonstrates the usage of GetPage to retrieve the PageData object for the current page.
EPiServer PageData tmpPageData = GetPage( CurrentPageLink );
The following code example demonstrates the usage of GetPage and CurrentPage to retrieve PageData information for the page specified in the EventsContainer attribute.
GetPage(PageReference, LoaderOptions)
Retrieves a PageData object based on supplied PageReference argument (from IPageSource).
Declaration
public virtual PageData GetPage(PageReference pageLink, LoaderOptions loaderOptions)
Parameters
Type | Name | Description |
---|---|---|
PageReference | pageLink | The page link. |
LoaderOptions | loaderOptions | The loader settings that is used to load the correct language and version of the page. |
Returns
Type | Description |
---|---|
PageData | Returns the PageData object for the specified PageReference argument. |
Examples
The following code example demonstrates the usage of GetPage to retrieve the PageData object for the current page.
EPiServer PageData tmpPageData = GetPage( CurrentPageLink );
The following code example demonstrates the usage of GetPage and CurrentPage to retrieve PageData information for the page specified in the EventsContainer attribute.
IsOptionEnabled(Int32)
Determines whether the specific page extension option is enabled.
Declaration
public bool IsOptionEnabled(int option)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | option | The option to check. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Remarks
option is the OptionFlag value for one of the page extensions defined with the [PagePlugIn] attribute.
IsValue(String)
Determine if the named property exists and has a value.
Declaration
public bool IsValue(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The name of the page property to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if the property exists with a valid (i e non-null) value. |
Remarks
IsValue can be seen as a safe way to check whether a property exists and has been assigned contents.
Examples
The following code example demonstrates the usage of CurrentPage and IsValue. CurrentPage is used to read the content of two properties; NewsCount and MainImage. To safeguard the property access, the presence and possible contents of both properties are first tested using the IsValue method.
LoadDisplayTemplate(BlockData)
Resolves and instantiates the web or user control for the BlockData.
Declaration
public virtual Control LoadDisplayTemplate(BlockData blockData)
Parameters
Type | Name | Description |
---|---|---|
BlockData | blockData | The block data to populate the control with. |
Returns
Type | Description |
---|---|
System.Web.UI.Control |
OnInit(EventArgs)
Raises the System.Web.UI.Control.Init event to initialize the page.
Declaration
protected override void OnInit(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e | An System.EventArgs that contains the event data. |
OnPreRenderComplete(EventArgs)
Raises the System.Web.UI.Page.PreRenderComplete event after the System.Web.UI.Page.OnPreRenderComplete(System.EventArgs) event and before the page is rendered.
Declaration
protected override void OnPreRenderComplete(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e | An System.EventArgs that contains the event data. |
Remarks
We override this method to make sure that EPiServers script manager can render the script blocks needed.
PrepareForSave()
Prepares the data for the page to be saved.
Declaration
[Obsolete("Save handler is no longer support, use regular IContentRepository API's to save content")]
protected virtual void PrepareForSave()
Remarks
Moves new data from web controls into the property objects or CurrentPage and also triggers the global validators.
QueryAccess()
The access level that the current user holds to the current page.
Declaration
public virtual AccessLevel QueryAccess()
Returns
Type | Description |
---|---|
AccessLevel | The access level. |
Remarks
Will return the actual access level for the current page, or Read if there is no current page.
QueryDistinctAccess()
Verify that access control requirements are met for the current web request.
Declaration
public bool QueryDistinctAccess()
Returns
Type | Description |
---|---|
System.Boolean | True if access requirements are met. |
Remarks
This method simply checks that all bits set in RequiredAccess() are set in QueryAccess().
RegisterClientScriptFile(String)
Helper method to register a client script file. If the method is called multiple times using the same key, only a single instance of the file is registered.
Declaration
public void RegisterClientScriptFile(string rootRelativePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | rootRelativePath | The script file that should be referenced. |
Remarks
The relativePath will be used as the unique script key.
RequiredAccess()
Determine the access level that is required for the current web request.
Declaration
public virtual AccessLevel RequiredAccess()
Returns
Type | Description |
---|---|
AccessLevel | The resulting access level. |
Remarks
This is the default implementation that simply requests Read access, regardless of the type of requested operation.
ResolveUrlFromUI(String)
Resolves the path relative the UI directory.
Declaration
public string ResolveUrlFromUI(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path. |
Returns
Type | Description |
---|---|
System.String |
ResolveUrlFromUtil(String)
Resolves the path relative the Util directory.
Declaration
public string ResolveUrlFromUtil(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path. |
Returns
Type | Description |
---|---|
System.String |
SavePage()
Perfoms validation logic and then saves the current page.
Declaration
[Obsolete("Save handler is no longer support, use regular IContentRepository API's to save content")]
public virtual bool SavePage()
Returns
Type | Description |
---|---|
System.Boolean |
Remarks
This performs validation logic, and a save. If you must save without validation, use the SavePageHandler directly.
SetCachePolicy()
Sets the cache policy for this request based on parameters as current user and parameters.
Declaration
protected virtual void SetCachePolicy()
Remarks
Override this method if you wish to customize the cache policy for a page. The output cache is turned on based on the following criteria:
- The EPnCachePolicyTimeout in web.config is > 0.
- The current user must not be logged on, aka Anonymous.
- The request must be a GET type request. Hence, Postbacks and form postings will not be cached.
- The current page must be the published version (the WorkID is == 0).
The cache parameters are fetched from web.config, more specifically the EPsCacheVaryByCustom and EPsCacheVaryByParams settings. Additionally, a dependency to the DataFactoryCache is set. When pages are changed, the cache is flushed. Cache item expiration is set to the HttpCacheExpiration setting, which is the number of seconds the item should reside in the cache, as long as the StopPublish value of the page is not less than the policy timeout (in which case, the StopPublish value is used).
SetupVisitorGroupImpersonation()
Called to configure visitor group impersonation used from editing preview
Declaration
protected virtual void SetupVisitorGroupImpersonation()
SetValuesForPropertyControls(Control)
Get new data from property web controls into the actual property objects for all controls implementing IPropertyControl.
Declaration
public virtual void SetValuesForPropertyControls(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Web.UI.Control | control |
Remarks
Used to update PagaData values when saving a page.
Translate(String)
Translate the given string to the current language.
Declaration
protected virtual string Translate(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | A string to translate |
Returns
Type | Description |
---|---|
System.String | The translated string. |
Remarks
GetStringByCulture(String, CultureInfo) for more information on the format of the string to translate.
TranslateFallback(String, String)
Translate the given string to the current language. Will return supplied fallback string if no match is found.
Declaration
protected virtual string TranslateFallback(string key, string fallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | A string to translate |
System.String | fallback | The string to return if no match was found for key. |
Returns
Type | Description |
---|---|
System.String | The translated string. |
Remarks
GetStringByCulture(String, CultureInfo) for more information on the format of the string to translate.
TranslateForScript(String)
Translate the given string to the current language, in a script-safe format.
Declaration
protected virtual string TranslateForScript(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | A string to translate |
Returns
Type | Description |
---|---|
System.String | The translated string. |
Remarks
GetStringByCulture(String, CultureInfo) for more information on the format of the string to translate.
ValidatePageTemplate()
Makes sure that the right page template is used to present a page.
Declaration
public virtual void ValidatePageTemplate()
Remarks
This method is called as part of the page load process. If a page (as determined by the ID query string parameter on the URL) is accessed with an .aspx file that is not the correct page template file, this method will throw an exception of type EPiServerException. If you have a page type that should be displayed using different page templates, you should override this method and do your custom validation. A validation error should be signalled by throwing an EPiServerException.
Events
PageSetup
Exposes the PageSetup event which is raised when a new page instance is created.
Declaration
public static event PageSetupEventHandler PageSetup
Event Type
Type | Description |
---|---|
PageSetupEventHandler |
Remarks
Attach to this event to be able to attach your code to specific events in the page lifecycle, allowing for your page extension to extend any page that derives from PageBase with your custom code.
Explicit Interface Implementations
IContentSource.CurrentContent
Gets the content of the current page.
Declaration
IContent IContentSource.CurrentContent { get; }
Returns
Type | Description |
---|---|
IContent | The content of the current page. |