Use the value of a custom attribute

The values for custom page attributes are persisted together with other page properties, but are not displayed or used anywhere by default. It is up to you to decide how you want to use these values. The most common scenarios are in custom extensions and you can use the Pages API to access values in custom page attributes.

One example of using the value of a custom attribute is when handling the PreRenderComplete event for Sitefinity CMS pages. The following code demonstrates how to do this:

In the code above, you:

  1. Add a Global.asax file to your project.
  2. Subscribe for the PreRenderComplete event. You do this when the application starts, in the Global.asax file for your Sitefinity CMS project

    Sitefinity CMS fires certain events through the EventHub system, but you can only subscribe to these events after the application has been initialized. To make sure that the application is initialized, you can execute your code in the handle of the Bootstrapper.Bootstrapped event. The first thing to do is to subscribe to this event and have a handler for it.

  3. In the Bootstrapper_Bootstrapped handler, you can use the EventHub to subscribe to the IPagePreRenderCompleteEvent.
    For more information about using the EventHub, see Event system: EventHub.
  4. In the handler of the IPagePreRenderCompleteEvent event, you can access all custom page attributes through the method arguments. You can do so by accessing the Attributes property of the PageSiteNode object. You can use the name of the custom attribute you created as index, and this returns the value of the attribute.

After you have retrieved the value, you can use it any way you want.

NOTE: As developer, you can decide how you want to use the values of custom page attributes, but you can always access them through the Attributes collection of the PageSiteNode class.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?