Search code examples
asp.netsitecorepreview

How to access current Sitecore item in layout .aspx, while in preview pane in the Sitecore content editor?


I have put together an .aspx page which is the layout for a certain template. I cannot get the current item by path (i.e. by calling Database.GetItem(string)) while in the Sitecore preview pane, though it works fine on the web, even using the .NET Request.RawUrl property.

How do I most easily get access to the current item in this context?


Solution

  •  Sitecore.Context.Item 
    

    to get the item for the current page on Preview mode and on Normal mode.

    To check if you are on preview you can use :

    if (Sitecore.Context.PageMode.IsPreview) and 
    

    if is normal page you can use :

       if (Sitecore.Context.PageMode.IsNormal )