Does Kentico Auto-Prefix CDN Endpoint URLs to Media File Paths?

Patrick Taylor asked on August 21, 2018 22:03

Is anyone here familiar with using Azure or Amazon CDN services with Kentico media libraries? I have a client running Kentico v10.0.21 with Amazon CloudFront CDN in the web.config. https://docs.kentico.com/k10/custom-development/working-with-physical-files-using-the-api/configuring-file-system-providers/configuring-amazon-s3#ConfiguringAmazonS3-ConfiguringKenticotouseAmazonCloudFrontCDN

They're running into an issue where Kentico doesn't prefix the CDN Endpoint URL to media file paths. Is there any native Kentico functionality for auto-prefixing the CDN path to Media Library selections if the web.config was setup to use a CDN? I could use a custom macro to read the value from the web.config and do something with that, but it seems strange that this wouldn't be a native feature of Kentico if it already enables using CDN endpoints.

Correct Answer

Patrick Taylor answered on August 23, 2018 19:09

Dawid, thank you for that custom solution. I ended up discovering that this case is already handled by Kentico, so a custom solution is not necessary.

I configured a clean Kentico 10 web site to store only media files on Azure storage, (https://docs.kentico.com/k10/custom-development/working-with-physical-files-using-the-api/configuring-file-system-providers/configuring-azure-storage#ConfiguringAzurestorage-ConfiguringKenticotostoreonlymediafilesonAzurestorage). Then, I configured Kentico to use a CDN, (https://docs.kentico.com/k10/running-kentico-on-microsoft-azure/configuring-azure-cdn#ConfiguringAzureCDN-ConfiguringKenticotouseaCDN). These were not Amazon storage or CDN resources because we do not have an active Amazon Web Services (AWS) account, but they should mimic Kentico's general approach to media files and external storage providers. After completing those custom configuration tasks, I applied hotfix 10.0.21 to ensure the Kentico instance was running the same hotfix as our client.

I tested adding several media files. The media files always used an absolute URL for the direct path and relative URL for the permanent link. The direct path's absolute url always began with the CDN endpoint URL.

I tested adding media files to pages using the Rich Text widget on the page tab. The img tag's src attribute always used the direct path and always began with the CDN endpoint URL.

These tests confirm that Kentico already handles adding the CDN endpoint URL to the direct path of media files. If Kentico fails to prepend the CDN endpoint URL to the direct path of media files, then Kentico is not configured to use a CDN. If Kentico fails to prepend the cloud storage URL to the direct path of media files or uses relative URLs for the direct path of media files, then Kentico is not configured to store only media files on cloud storage.

I suspect that our client was neither configured to store media files on cloud storage nor to use a CDN.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Dawid Jachnik answered on August 22, 2018 08:31

Have you tried with custom solution?You have use rewrite module in web config

<rewrite>
  <outboundRules>
    <rule name="Rewrite media to cdn" preCondition="IsHTML">
      <match filterByTags="Img" pattern="/getmedia/(.*)" />
      <action type="Rewrite" value="https://yourcdn.domain/getmedia/{R:1}" />
    </rule>
    <rule name="Rewrite media files to cdn by path" preCondition="IsHTML">
      <match filterByTags="Img" pattern="/yourwebsitename/media/(.*)" />
      <action type="Rewrite" value="https://yourcdn.domain/yourwebsitename/media/{R:1}" />
    </rule>
  </outboundRules>
</rewrite>
0 votesVote for this answer Mark as a Correct answer

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