Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Gregory 404 posts 1557 karma points MVP 2x admin c-trib
    Dec 09, 2014 @ 05:58
    Peter Gregory
    1

    Umbraco 7.2 preview not working, UmbracoUser user null.

    Hi there. This is probably going to be one of those posts that gets no responses because I'm probably the only person experiencing it but here goes.

    I have a site that started out life as a 7.1.4 and has now been upgraded to 7.2 release.

    The preview has not worked the whole time. If you hit preview on a node that is saved but not published you will get a 404 in the preview pane. If its a piece of content that you have published but have made updates to you only get the published content in the preview.

    So today I decided to debug the whole request to see what was going on. There is a method in the source that checks to see if the site is in preview mode UmbracoContext class that looks like this.

        public bool InPreviewMode
        {
            get { return _previewing ?? (_previewing = DetectInPreviewModeFromRequest()).Value; }
            set { _previewing = value; }
        }
    
        private bool DetectInPreviewModeFromRequest()
        {
          var request = GetRequestFromContext();
            if (request == null || request.Url == null)
                return false;
    
            var currentUrl = request.Url.AbsolutePath;
            // zb-00004 #29956 : refactor cookies names & handling
            return
                //StateHelper.Cookies.Preview.HasValue // has preview cookie
                HttpContext.Request.HasPreviewCookie()
                && currentUrl.StartsWith(IOHelper.ResolveUrl(SystemDirectories.Umbraco)) == false
                && UmbracoUser != null; // has user
        }
    

    The property InPreviewMode is used to determine if the site is currently in preview. Other methods including the part of the site that determines which cache to return use this.

    So I debugged this method. What i found was when it gets to the last part of the DetectInPreviewModeFromRequest() method it does a series of checks.

    1. Does it have a preview cookie
    2. Make sure its not a system directory that we are requesting
    3. Are we logged in as an Umbraco admin user

    1 & 2 pass. Yes I do have a preview cookie. No the page I am loading is not a back office page. But 3 gets returned as Null when I am in the request that is for the actual page I want to preview, so the site says I am not in preview and the Umbraco returns a 404. Dang :(.

    What makes no sense is that every request for all the back office panes (responsive preview etc) all return an UmbracoUser when going through the same method. So my problem is only with the content that is loading into the iFrame on the right.

    Diving deeper into UmbracoUser I get as deep as finding that in WebSecurity.cs the method GetUserId() that when it tries to get the identity from the httpContext (found in the AuthenicationExtensions.cs in the GetCurrentIdentity() that User property of the HttpContext is Null.

    This is where Im getting a little stumped. Why would this be? If anyone has any thoughts on this? Maybe Shannon or Stephan might have some clues?

  • Peter Gregory 404 posts 1557 karma points MVP 2x admin c-trib
    Dec 09, 2014 @ 06:36
    Peter Gregory
    100

    So I just resolved my own problem

    I had a custom Module that switched the site the HTTPS if the page needs to be secure. It was messing with the request. So now I am working on a different way of doing it on the page rather at such a low level.

    Cheers ME for finding that and Shannon for being a sounding board.

  • Andrei 64 posts 115 karma points
    Apr 20, 2015 @ 13:53
    Andrei
    0

    Same problem here but without a module messing the request. Any suggestions

Please Sign in or register to post replies

Write your reply to:

Draft