Kentico cache null reference - causing images not to be load

jeff McDaniel asked on May 12, 2017 00:21

Hi everyone,

I've been dealing with a very strange issue and have had no luck troubleshooting it. It is one of the stranger things I've seen with my sites.

My problem is with images and the favicon on my webpages. If you go to any of the webpages, they will all show Xs on each image and the console log shows a 404 error when trying to load them. This is for each one including the favicon, and it appears that way for each browser.

Eventually through playing around with it I have discovered that the images load for me if I login to Kentico's admin interface and view the page through there. After that I have no problem the images will load in the same browser that I went to Kentico in. However, the images still are not shown for external users/people who haven't been in the Kentico backend interface.

Each browser acts the same way, logging into Kentico will show the images and fix the issue but only for that specific person and on that specific browser.

I tried logging into the server itself and hitting the webpage and I got a 500 error. This showed up in the event log as a bit more descriptive.

`Message: Object reference not set to an instance of an object.

Exception type: System.NullReferenceException Stack trace: at CMS.Helpers.CacheHelper.GetUserCacheKey() at CMS.Helpers.CacheHelper.GetBaseCacheKey(Boolean userName, Boolean cultureCode) at CMS.Routing.Web.AdvancedGetFileHandler.GetBaseCacheKey() at CMS.DocumentEngine.GetAttachmentHandler.ProcessAttachmentCached() at CMS.DocumentEngine.GetAttachmentHandler.ProcessRequestInternal(HttpContextBase context) at CMS.Routing.Web.AdvancedGetFileHandler.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)`

It appears something is broken with my Kentico cache. I haven't found a solution to this. I've tried the following fixes but I am still seeing the same thing.

  1. Clear cache, restart application, restart IIS, clear browser cache.
  2. Reset images from back end, delete and stage from lower environment, try new images.
  3. Restore database from environment where this is working, restore back end Kentico code, and change web config to copy exactly except for DB connection.

All 3 had the same result. I don't know too much about the cache, but #3 leads me to believe that maybe something is blocking Kentico from accessing it's cache in a public setting? Does anyone have any ideas for troubleshooting I can do with this? I'd appreciate the help!

Thanks Jeff

Correct Answer

jeff McDaniel answered on June 16, 2017 19:21

Hi everyone,

This issue was due to multiple forms of authentication in our web config. Before the upgrade, we were trying to test out a new way to connect to our security service.

<add name="SessionAuthentication" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
      <add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" /> 

These were old lines that we needed to comment out to get the images to load properly again.

Jeff

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on May 12, 2017 02:49

Was the site running fine before or has it always done this?

Do you have security setup on the media library or pages?

Do you have permissions granted on the server directory for the user running IIS to have read access to the directories?

1 votesVote for this answer Mark as a Correct answer

jeff McDaniel answered on May 12, 2017 17:27

Hi Brenden,

Thanks for the response.

Yeah, they were fine before this happened. I also do not have any special security cases on the pages and made sure to grant my app pool to have modify permissions on the entire CMS directory just to be safe.

It sounds like it is something like one of the three though or maybe even a server issue.

Thanks Jeff

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 15, 2017 15:47

Hi,
What is the exact Kentico version you are using?
Also, what is the generated URL for the image when you inspect it on the live site - I mean the broken URL. Versus what is the URL when logged in?

I would also check the Extensionless and custom URL setup - the settings in Kentico UI as well as the web.config setup.

Also, the referenced image - is it from a media library or from the content tree? (either CMS.File page or page attachment).

Last but not least - just to get bigger picture, what are the caching options used in your Kentico instance?

Thanks!

0 votesVote for this answer Mark as a Correct answer

jeff McDaniel answered on May 16, 2017 22:07

Hi Juraj,

Thanks for the response. You can find your answers below.

We are on Kentico 10.0.19.

The generated URL that is throwing a 404 error is /404.aspx?aspxerrorpath=/CMSPages/getfile.aspx. That is from the outside source. If I go to the webpage on the same server that my IIS is hosted, I get this error. GET https://[servername.net]/img/ahhealthathomelogo150.png 500 (Internal Server Error)

I had some extensions in the friendly URL extensions and having nothing in there, and they both throw the same error. For the record I have modules runAllManagedModulesForAllRequests="true" in my web config and going to https://[servername.net]/img/ahhealthathomelogo150.png or https://[servername.net]/img/ahhealthathomelogo150 returns the same error.

Each of these images are files on the site itself. They are referenced through editableimages.

My cached (settings -> system -> performance) options are the default Kentico options.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 17, 2017 15:19

It is strange that you are getting 500 error - this means the web server, IIS, is not configured correctly. Have you checked the setup and settings? For example the mime types, handler mappings, etc. On the same IIS, when you create a non Kentico web site, place some static html or image file, are you able to browse them?

0 votesVote for this answer Mark as a Correct answer

jeff McDaniel answered on June 14, 2017 00:11

Hi Juraj,

We had some other things come up and this has come back to my queue. I was checking out my IIS and it looked okay. All of my settings, mime types, handler mapping etc are the default versions. I tried removing the web sites and re-adding new ones and have run into the same problem with the Kentico cache. Is there something I should be looking for specifically?

I also have several other Kentico installations on the same IIS server, and they can load images/html successfully. It is just this one installation. The event log mentions an error detailing with a user cache key. The cache sets correctly and the images load fine when the user logs into Kentico back end admin interface. It only happens for users that have not logged into the admin interface, or are viewing the site publicly. Is it possible that the User 'public' cache key is corrupted from the back end?

CMS.Helpers.CacheHelper.GetUserCacheKey()
at CMS.Helpers.CacheHelper.GetBaseCacheKey(Boolean userName, Boolean cultureCode)

Thanks, Jeff

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on June 14, 2017 08:29

Hi,
Thanks for the details. I am unable to reproduce the issue. I would need to know the exact setup and configuration and the steps how to reproduce this issue. Also, what is different here if other web sites are working fine?

0 votesVote for this answer Mark as a Correct answer

jeff McDaniel answered on June 14, 2017 19:27

Hi Juraj,

What details are you looking at? And there wouldn't be any major difference. We have the same default IIS settings, and same system cache settings. We do have custom code but it doesn't deal with system cache and loading images.

We have separate Kentico installations on the same server but this installation is the only one having this problem. I tried taking the Kentico code and database from the working production server and copying it over the broken staging server, and the problem still existed.

I exported my cache settings (system -> performance)

Global settings, category "System > Performance"

General

Enable output compression: False

Server content caching

Cache page info (minutes): 10

Cache content (minutes): 10

Use progressive caching: True

Server file caching

Cache files (minutes): 10

Maximum file size to cache: 200

Redirect files to disk: False

Client caching

Client cache (minutes): 30

Allow client cache revalidation: True

Output caching

Enable output caching: True

Cache output in file system (minutes):

Output cache variables: username,True;sitename,True;lang,True;browser,True;cookielevel,True;deviceprofile,True;domain,False;viewmode,False

Enable partial caching: True

Partial cache variables:

Resources

Allow resource compression: False

Allow JavaScript minification: True

Allow CSS minification: True

CSS Styles

Resolve macros in CSS: True

Allow CSS from components: True

Combine CSS from components: False

Here is the two events in the event log that I exported.

EventID: 1636324

EventType: W

EventTime: 6/14/2017 11:17:32 AM

Source: Application_Error

EventCode: PAGENOTFOUND

UserID: 65

UserName: public

IPAddress: 10.5.2.82

Site: staging_ascensionathome_com

EventUrl: /404.aspx?aspxerrorpath=/CMSPages/getfile.aspx

EventMachineName: DDC-WEBSTAGE01

EventUserAgent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0

EventID: 1636323

EventType: E

EventTime: 6/14/2017 11:17:32 AM

Source: Application_Error

EventCode: EXCEPTION

UserID: 65

UserName: public

IPAddress: 10.5.2.82

EventDescription: Message: Object reference not set to an instance of an object.

Exception type: System.NullReferenceException Stack trace: at CMS.Helpers.CacheHelper.GetUserCacheKey() at CMS.Helpers.CacheHelper.GetBaseCacheKey(Boolean userName, Boolean cultureCode) at CMS.Helpers.CacheHelper.get_BaseCacheKey() at CMS.Routing.Web.AdvancedGetFileHandler.GetBaseCacheKey() at CMS.DocumentEngine.GetAttachmentHandler.ProcessAttachmentCached() at CMS.DocumentEngine.GetAttachmentHandler.ProcessRequestInternal(HttpContextBase context) at CMS.Routing.Web.AdvancedGetFileHandler.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

EventUrl: /img/favicon.ico

EventMachineName: DDC-WEBSTAGE01

EventUserAgent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0

What else would you like me to export for these settings? Many of the issues are coming from the /getattachment but the get attachment doesn't appear to have a valid url with it.

Jeff

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.