Page Attachment Url throwing 404

PITO Web CMS asked on February 4, 2021 17:54

We are running Kentico MVC 13.0.7 and are using page builder / templates / widgets to generate most of our content. The page type has a "Teaser Image" field that is a file attachment and we are attempting to use that in the template.

When we create a new page or update the image field in the pages app, it shows the image in the content tab and can link to the image directly. The link that works and generally follows the url pattern {Admin Project Domain}/getattachment/{file guid}/{filename}.{extension}?chset={different guid}

In the site project, we are getting a strongly typed object from the page type's generated code, PageProvider.GetPage(nodeId, "en-US", siteName).LatestVersion(); Then using the dependency injected IPageAttachmentUrlRetriever to get the "TeaserImage" url.

pageAttachmentUrlRetriever.Retrieve(pageWithTeaserImage.Fields.TeaserImage).AbsoluteUrl;

The URL we get from this call tends to follow the pattern: {Site Project Domain}/cmsctx/pm/8b0ef3be-54bd-4a89-b60f-ac2213b839b0/culture/en-US/wg/332799f7-38b9-4814-992b-2183229d3d73/readonly/0/ea/1/h/dc08cbb2257bbb701efbbdd96b55472535771b0352fc03da19d56fa36d85f755/-/getattachment/64bf4c9d-6152-4b63-9148-212237aacce1/{fileName}.{extension}?uh=65dce9456213d29747639b306244020f2a4e69dbe559c161bc67feeb1061fc9b&administrationurl=https%3A%2F%2F{Admin Project Domain Encoded}

The only issue is that the url provided {relative or absolute} results in a 404 response from the site project.

Any suggestions on something I can check to maybe get these urls to resolve?

David PITO WebCMS Team TAMU

Recent Answers


Laura Frese answered on February 6, 2021 21:37

Its best practices to use the media library to select images in widgets. However, if you want to load an attachment image from your live site then the path to use would be {liveSiteDomain}/getattachment/{fileGUID}/{fileGUID.ext} ie https://mysite.com/getattachment/060B7A50-D886-426F-BF98-62267A89F017/060B7A50-D886-426F-BF98-62267A89F017.jpg

Also "To ensure that attachment URLs work correctly in both the MVC application and the connected Kentico administration interface, the system must be configured to use the permanent URL format. MVC sites have permanent URLs enabled by default"

Documentation on page attachments here https://docs.xperience.io/developing-websites/retrieving-content/displaying-page-attachments

0 votesVote for this answer Mark as a Correct answer

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