Cannot view images or load scripts from MVC application in page builder preview.

Mark Clark asked on February 11, 2019 09:57

Images that load just fine on the MVC site directly will not load in the page builder preview. The Kentico event log has the following entry for every missing resource: Relative path hash validation has failed.

The urls on the view typically follow the format: @Url.Kentico().ImageUrl("SITE_NAME/media/MEDIA_LIBRARY/sub_directory/image.jpg", SizeConstraint.Empty)

The resulting link (which looks the same as the input) works perfectly fine when accessed from the presentation site, but it 404s in the Pages application preview.

The base css and root scripts are loading fine however they are using the format /CMSPages/GetResource.ashx?stylesheetfile=ENCODEDFILENAME and /CMSPages/GetResource.ashx?scriptfile=ENCODEDFILENAME

I get a similar error when trying to add a custom inline-editor widget (implemented by following DancingGoatMvc example and related docs).

The src attributes are showing the same url that resolves on the presentation site however the network log shows a different request URL https://PRESENTATION_SITE_DOMAIN/cmsctx/pv/administrator/culture/en-US/wg/43cc737e-3e48-4d82-bf2b-180f124bd565/readonly/0/ea/1/h/f318b377cdec5a782cebafa1dfc2d36bcf938436810687c829a7ee728

Correct Answer

Mark Clark answered on February 19, 2019 19:35

Additional update: The inline editor issue was caused by setting BundleTable.EnableOptimizations = true; in the bundle config. Don't know why this broke the page builder's inline editor (specifically our implementation of ckEditor, simpler widgets were still working) nor do I know if it would break on a release/non-debug build as that should enable optimizations as well. Cause is currently being investigated.

(As only one answer can be selected, see Juraj's answer below for the solution to static images 404ing.)

1 votesVote for this answer Unmark Correct answer

Recent Answers


Juraj Ondrus answered on February 11, 2019 14:20

Hi,
Could you please double check that the Presentation URL set for your MVC site is correct? This URL is used in the page builder - so maybe there is some mistake.

0 votesVote for this answer Mark as a Correct answer

Mark Clark answered on February 11, 2019 15:16 (last edited on February 11, 2019 15:16)

Site domain: local.project-name

Presentation URL: https://local.project-name

I have the above domain setup in my hosts file to point to 127.0.0.1 and have a domain alias on this site for localhost because I am using localhost to access the admin portal.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on February 11, 2019 15:19

So, if the presentation URL matches your MVC application's web site IIS setup, then I would check the hash string salt in the Kentico and MVC apps - in the web.config files and make sure they are the same and then, re-sign the macros in Kentico.

0 votesVote for this answer Mark as a Correct answer

Mark Clark answered on February 11, 2019 15:39

Resigned all macros, no change.

Here is a screen capture of the event log error

It's happening for fonts, images and scripts that are referenced by relative path only when attempted to load from page builder preview.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on February 11, 2019 21:04

It's not about resigning though, i would indeed verify that you have the same hash string salt in the appkey's of your web.config for both kentico and mvc, as that usually is what generates that error.

If that isn't the case, make sure that you have Kentico's Route set up in the route config so it properly handles the /ctx routing path. Step 5 of this document.

0 votesVote for this answer Mark as a Correct answer

Mark Clark answered on February 11, 2019 21:28

Verified salts are identical. Step 5's contents are present, similar to the DancingGoatMvc I referenced; however, I noticed I don't have any hotfixes which addresses some page builder issues. Applying and will report back.

0 votesVote for this answer Mark as a Correct answer

Mark Clark answered on February 11, 2019 22:04

Updated to 12.0.9 and the problem persists.

Does routes.Kentico().MapRoutes(); handle mapping file urls from the MVC app that aren't done via controller? If I am not having to do anything special for the direct url, it should work for the preview too, right?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on February 15, 2019 11:20

Just an update on this for others. The image issue was resolved by using relative paths for the resources, e.g. @Url.Content("~/media/logo.png") the "Relative path hash validation has failed" error seems to be a separate issue and we are currently investigating it with our developers.

0 votesVote for this answer Mark as a Correct answer

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