6

We have deployed a jss app to a Content Delivery server.

We have followed instructions to add jss support to the server role.

Links to media items generated by Image components begin with /-/jssmedia and 404.

Changing the generated urls to start with /-/media makes them serve an image.

The error in the logs for broken links is this:

3392 11:43:27 ERROR Application error.
Exception: System.Web.HttpException
Message: The file '/-/jssmedia/cms-sitecore/data/media/img/sitecorejss_media.ashx' does not exist.
Source: System.Web
   at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate)
   at System.Web.UI.SimpleHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
   at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

IIS Handler Mappings

On the Content Delivery server, IIS Site > Handler Mappings shows the sitecore_media.ashx endpoint. It does not have a sitecorejss_media.ashx endpoint.

On a Content Management server, where the images are showing up, the sitecorejss_media.ashx endpoint is registered.

3 Answers 3

7

What we did:

Located the file Sitecore.JavaScriptServices.MediaRequestHandler.jssconfig in the App_Config directory.

Pulled out the line where it defines the handler, and added it to end of the system.webServer/handlers section of the root web.config.

The patch looks like this:

      <add verb="*" path="sitecore_expeditor_speak_request_async.ashx" type="Sitecore.ExperienceEditor.Speak.Server.RequestAsyncHandler, Sitecore.ExperienceEditor.Speak" name="Sitecore.ExperienceEditor.Speak.Server.RequestAsyncHandler" />
      <add verb="*" path="sitecorejss_media.ashx" type="Sitecore.JavaScriptServices.Media.MediaRequestHandler, Sitecore.JavaScriptServices.Media" name="Sitecore.JavaScriptServices.Media.MediaRequestHandler" />
    </handlers>
0

The reason is if you didn't install the Headless Services module the normal way on that environment then you have to manually update the Web.config as per

https://doc.sitecore.com/xp/en/developers/hd/201/sitecore-headless-development/media-handler.html

0

We had this same issue but in containers.

What is missing is somehow the handler that is written in "Sitecore.XA.Foundation.MediaRequestHandler.sxaconfig" file in /App_Config folder is not getting applied to the web.config file. So for non-docker setup we can simply copy the below line and add it to 'system.webServer/handlers' section of the root web.config.

<add patch:instead="*[@type='Sitecore.Resources.Media.MediaRequestHandler, Sitecore.Kernel']" verb="*" path="sitecore_media.ashx" type="Sitecore.XA.Foundation.MediaRequestHandler.MediaRequestHandler, Sitecore.XA.Foundation.MediaRequestHandler" name="Sitecore.MediaRequestHandler" />

Now if you are using Docker as in our case, we wrote a xdt for the same and it worked for us.

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.webServer>
    <handlers>
      <add verb="*" path="sitecorejss_media.ashx" type="Sitecore.JavaScriptServices.Media.MediaRequestHandler, Sitecore.JavaScriptServices.Media"
         name="Sitecore.JavaScriptServices.Media.MediaRequestHandler" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" />
    </handlers>
  </system.webServer>
</configuration>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.