When an item is set to unpublishable, all methods to get the item for a rendering with GlassMapper return null.

public class PageHeaderController : GlassController
    public override ActionResult Header()
        BaseItem model = SitecoreContext.GetCurrentItem<BasePage>(); // null
        model = GetLayoutItem<BasePage>(); // null
        model = SitecoreContext.GetItem<BasePage>(RenderingContext.Current.Rendering.DataSource); // null
        return View(model);

How can we get the item in that case to be able to provide a publishing preview for editors for items that are set to be published in the future?

The problem occurs whether we use the "Never Publish" setting or set the version to unpublishable or even when the version is set to be published in the future.

The preview is really running with the master database.enter image description here

  • How do you obtain SitecoreContext? From what I know there is no static method SitecoreContext.GetCurrentItem?
    – Marek Musielak
    Commented Mar 27, 2017 at 14:12
  • @MarekMusielak SitecoreContext is a member of Glass.Mapper.Sc.Web.Mvc.GlassController.
    – Residuum
    Commented Mar 27, 2017 at 14:29
  • Right, I missed that.
    – Marek Musielak
    Commented Mar 27, 2017 at 14:37
  • I just want to make sure that I am understanding your question correctly. The business case is that your authors create an item, but said item is not yet ready for publishing. Either via custom workflow, Standard Values, manual setting by the authors, etc. the "Never Publish" field is checked to prevent accidental/premature publishing. However, the authors want to be able to view the rendered page for the item using the "Preview" feature. Is that correct? Commented Mar 27, 2017 at 15:12
  • 1
    Just out of curiosity, is there any reason why you are using the "Never Publish" setting for this rather than using Workflow? I can post this with further detail as an answer but only if you request it, since it doesn't technically answer your original question. doc.sitecore.net/sitecore_experience_platform/content_authoring/… Commented Mar 27, 2017 at 15:45

1 Answer 1


This is normal behavior for the Preview feature. The purpose of this feature is to show you what the page will look like once published. Therefore the behavior you're encountering sort of makes sense, considering the page would simply not be published. To be fair, a more graceful approach (e.g. warning message) would be appreciated.

There are a couple of ways to get around it.

(1) If it's just for a one-off preview, you can change the preview URL like so. If Sitecore generates:


Change it to:


Note the sc_mode and sc_database parameters.

(2) In code, you could disable site filtering by setting Sitecore.Context.Site.DisableFiltering to true. More details in this answer here: https://stackoverflow.com/a/20390596/1327412

  • unfortunately GlassMapper, or at least the implementation I'm using, does not factor in the setting Sitecore.Context.Site.DisableFiltering, so anytime we try to cast the Never Publish item into a Glass entity, it will return null. Commented Feb 8, 2022 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.