Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've found a way around this for cases where you <em>really</em> need to read from the <code>ContentDatabase</code> (i.e. master database) and don't want items to publish. This could be user generated content, for example. In Active Commerce, we run into this with content such as Wish Lists which are always read from master in preview or non-staged environments, and are accessed via web service in staged environments.</p> <p>By setting <code>Sitecore.Context.Site.DisableFiltering</code> to <code>true</code>, the filtering of unpublishable items will be disabled. I've implemented a simple <code>IDisposable</code> that allows you to temporarily disable filtering, with an optional condition.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ActiveCommerce.SitecoreX { public class ItemFilteringDisabler : IDisposable { private readonly bool _disableCondition = true; public ItemFilteringDisabler() { Sitecore.Context.Site.DisableFiltering = true; } public ItemFilteringDisabler(bool disableCondition) { _disableCondition = disableCondition; if (_disableCondition) { Sitecore.Context.Site.DisableFiltering = true; } } public void Dispose() { if (_disableCondition) { Sitecore.Context.Site.DisableFiltering = false; } } } } </code></pre> <p>Example use:</p> <pre><code>using (new ItemFilteringDisabler(!Sitecore.Context.PageMode.IsNormal)) { Sitecore.Data.Database.GetDatabase("master").GetItem("{itemID}"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload