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.
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.
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.
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).
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;
}
}
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.
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?
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.
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
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.
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.
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).
Hi Jesse,
I assume that you subscribe to this event :
I don't see a check in your code to see if it's a removal or a refresh.
Can you try this :
Dave
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.
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
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?Also for clarity, this issue only occurs on the front end servers. The admin side works as expected.
is working on a reply...