Use a cache substitution widget

To substitute the cache for a particular widget, you create a custom cache substitution widget and place it on the page. The widget utilizes the ASP.NET cache substitution. You create a static method that registers with the ASP.NET implementation of cache substitution. Inside this method, you must render the content of the widget.

Create the widget markup

Create a User widget with the following markup:

Implement the code behind

If the widget, you want to substitute, inherits from SimpleView, which in turn inherits from System.Web.UI.WebControls.WebControl, you can override the RenderContents(System.Web.UI.HtmlTextWriter writer) method. Inside, you call your own implementation for performing cache substitution.

When output cache is used on the page, you substitute it with the CacheSubstitutionWrapper in DoPostCacheSubstitution() method by forming a dictionary of parameters and passing it to a CacheSubstitutionWrapper.RenderMarkupDelegate that afterwards renders the correct markup.

IMPORTANT: Do not pass entire objects, such as a page, a control instance, property of the control, etc. This will cause serious memory leaks. When you need to pass a property value, you must use its string representation.

Following is a code sample of the code-behind file:

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?