Copied to clipboard

Flag this post as spam?

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


  • Jesse Andrews 191 posts 716 karma points c-trib
    Apr 11, 2018 @ 00:00
    Jesse Andrews
    0

    How do you generate html version of 500 error page on front end servers of load balanced environment?

    Umbraco 7.8.1

    Currently, I can generate the html version on the admin environment, but haven't found a way to generate that file on the front end servers. I'm doing this so that the 500 error page will remain available when an error occurs that would break the error template as well. Are there any events that I can tie into this? I tried using the cacheUpdated event, but that only fires on the admin server.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 11, 2018 @ 06:18
    Dave Woestenborghs
    0

    Hi Jesse,

    Which event are you using. You are saying Cache updated event. This should fire on the loadbalanced server. If it doesn't fire this means that content is not updated as well.

    Dave

  • Jesse Andrews 191 posts 716 karma points c-trib
    Apr 11, 2018 @ 20:41
    Jesse Andrews
    0

    Hi Dave,

    Thanks for responding, though I think I've found the issue. We are using CacheRefresherBase<PageCacheRefresher>.CacheUpdated, but I forgot that we didn't have caching enabled on our staging environment (it's automatically updated with transforms when deploying to production to avoid caching causing issues when developing locally). I tested again and confirmed that the event is triggering.

    Will post an update later today on whether I was able to resolve the issue.

  • Jesse Andrews 191 posts 716 karma points c-trib
    Apr 12, 2018 @ 01:46
    Jesse Andrews
    0

    That resolved my cache event issue, but I'm encountering an error getting the data I need to check whether an html file should be generated (need the doc type alias and one of the properties). Currently we have the following.

    var id = (int)e.MessageObject;
    try {
        var content = UmbracoContext.Current.ContentCache.GetById(id);
        if (content != null) {
             HttpResponse.RemoveOutputCacheItem(content.Url);
             Helper.RemoveItemFromDonutCache(content.ContentType.Alias);
             if (content.DocumentTypeAlias == "error" && content.GetPropertyValue<int>("responseCode") == 500) {
                 ConvertToHtml(content.Url, "error-500");
             }
         }
     } catch (Exception ex) {
         LogHelper.Error<ApplicationHandler>($"Failed remove cache for node with id '{id}':", ex);
    }
    

    It throws a null reference exception, presumably because the id doesn't exist in the content cache, causing GetById to complain. I know the MessageObject itself isn't null, as the id does show up in the logged error. Do you have an idea on how to solve this? This solution was working at one point, but it may have broken after we updated umbraco (was originally on 7.4 when we first built the site).

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 12, 2018 @ 05:57
    Dave Woestenborghs
    0

    Hi Jesse,

    I assume that you subscribe to this event :

    PageCacheRefresher.CacheUpdated += this.PageCacheRefresherCacheUpdated;
    

    I don't see a check in your code to see if it's a removal or a refresh.

    Can you try this :

    private void PageCacheRefresherCacheUpdated(PageCacheRefresher sender, CacheRefresherEventArgs e)
            {
                if (UmbracoContext.Current == null)
                {
                    return;
                }
    
                switch (e.MessageType)
                {
                    case MessageType.RefreshById:               
                        var contentId = (int)e.MessageObject;                    
                        var item = UmbracoContext.Current.ContentCache.GetById(contentId);                   
                        if (item != null)
                        {
                            // your code here
                        }                    
    
                        break;
                    case MessageType.RefreshByInstance:                
                        var content = e.MessageObject as IContent;
                        if (content == null)
                        {
                            return;
                        }
    
                        // your code here
    
                        break;
                    default:
                        break;
                }
            }
    

    Dave

  • Jesse Andrews 191 posts 716 karma points c-trib
    Apr 12, 2018 @ 16:45
    Jesse Andrews
    0

    Woops. I missed including that in my code. We do have that check, and the MessageType is RefreshById. Another of our developers looked into this and confirmed the issue was that UmbracoContext.Current was null, which is what caused the error. Is there a way to determine the doc type alias of the node that triggered the cache request in this case? I can work around this with a hard coded id if there isn't.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 13, 2018 @ 05:40
    Dave Woestenborghs
    0

    Hi Jesse,

    Strange that Umbraco.Context is null.

    This is never null at my side when the event is hit. Can you specify which CacheRefresher your are binding to ?

    Dave

  • Jesse Andrews 191 posts 716 karma points c-trib
    Apr 13, 2018 @ 17:00
    Jesse Andrews
    0

    We are binding to PageCacheRefresher, though the syntax we are using is a little different than what you have. We bound to CacheRefresherBase<PageCacheRefresher>.CacheUpdated while yours binds directly to the PageCacheRefresher. Is there difference in behavior between the two?

  • Jesse Andrews 191 posts 716 karma points c-trib
    Apr 13, 2018 @ 17:05
    Jesse Andrews
    0

    Also for clarity, this issue only occurs on the front end servers. The admin side works as expected.

Please Sign in or register to post replies

Write your reply to:

Draft