Detecting the Sitefinity Environment (Backend, Design, Preview, Edit) with the SystemManager

By in
No comments

The Sitefinity SystemManager is a helper class that simplifies working within the Sitefinity system.

Although it supports several advanced operations (such as loading configuration settings, registering web services, etc.) one of it’s most helpful features is the ability to report the current environment in which your code is executing.

This is done through several helpful static properties that you can call directly alongside your executing code, and return boolean values based on the current request.

Using these properties will let you detect the current mode of the Sitefinity page, and adjust the behavior of your control as needed, such disabling run-time code while in Preview or Edit mode.

Here are a few of the more helpful properties that are fairly self-explanatory:

  • SystemManager.IsDesignMode
  • SystemManager.IsPreviewMode
  • SystemManager.IsBrowseAndEditMode
  • SystemManager.IsInLoadBalancingMode

Be sure to include the required Telerik.Sitefinity.Services namespace in your code.

User Control Extensions

To make things even easier, Sitefinity also includes a number of User Control extensions in the System.Web.UI namespace, which wrap the above properties into helper methods.

This allows you to check these more intuitively from your controls by simply using the this keyword, such as:

  • this.IsBackend()
  • this.IsDesignMode()
  • this.IsPreviewMode()

Be sure to reference the System.Web.UI namespace on your User Controls (which is usually automatically done by Visual Studio).

API Reference

Although listed above are some of the more helpful methods and properties available, this list can change change, and might certainly grow with future releases.

For a complete, updated list of all the methods and properties exposed by both the SystemManager and the UserControl extensions, I encourage you to always install the full Sitefinity API Reference which is included with the Sitefinity SDK.

Also highly recommended is a copy of Telerik’s free JustDecompile utility, which will let you dig even deeper into the features exposed by these (and many other) Sitefinity objects.

The following two tabs change content below.

selaromdotnet

Senior Developer at iD Tech
Josh loves all things Microsoft and Windows, and develops solutions for Web, Desktop and Mobile using the .NET Framework, Azure, UWP and everything else in the Microsoft Stack. His other passion is music, and in his spare time Josh spins and produces electronic music under the name DJ SelArom. His other passion is music, and in his spare time Josh spins and produces electronic music under the name DJ SelArom.