1

We've implemented error handling for missing images in Sitecore like so:

https://nourestani.wordpress.com/2015/05/11/error-executing-child-request-sitecore-for-404-useserversideredirect-transferrequest-vs-transfer/ which came from this post by Michael West: How do you setup a 404 and 500 error page for missing files and media items?.

This all works fine on CD servers, but we've seen an issue where on CA we get an error:

Could not find method: Process. Pipeline: /sitecore[database="SqlServer" xmlns:patch="http://www.sitecore.net/xmlconfig/"]/pipelines/httpRequestBegin/processor[type="Custom.Sitecore.Extensions.Pipelines.CustomMediaRequestHandler, Custom.Sitecore.Extensions" patch:source="Custom.Pipelines.config"

I've triple checked there are no issues with typos or anything as described here:

https://chrisperks.co/2017/03/05/error-could-not-find-method-process-pipeline-sitecoredatabasesqlserver-xmlnspatchhttpwww-sitecore-netxmlconfigpipelinesmvc-resultexecutingpatchsourcesitecore-mvc-config/

I've solved this by only deploying this patch in our CD config and not our CA config as it isn't a much of an issue on CA. However I'd like to resolve this for CA also and understand if we've missed anything or there is a better approach for this.

Further info:

Our Patch:

    <pipelines>
        <httpRequestBegin>
            <!--fix issue with missing media files throwing errors in logs-->
            <processor type="Custom.Sitecore.Extensions.Pipelines.CustomMediaRequestHandler, Custom.Sitecore.Extensions" />
        </httpRequestBegin>
    </pipelines>

The Pipline:

public class CustomMediaRequestHandler : MediaRequestHandler
    {
        protected override bool DoProcessRequest(HttpContext context)
        {
            Assert.ArgumentNotNull(context, "context");

            MediaRequest request = MediaManager.ParseMediaRequest(context.Request);

            if (request == null)
                return false;

            Media media = MediaManager.GetMedia(request.MediaUri);

            if (media != null)
                return DoProcessRequest(context, request, media);

            using (new SecurityDisabler())
                media = MediaManager.GetMedia(request.MediaUri);

            string str;

            if (media == null)
            {
                str = Settings.ItemNotFoundUrl;
            }
            else
            {
                Assert.IsNotNull(Context.Site, "site");
                str = Context.Site.LoginPage != string.Empty ? Context.Site.LoginPage : Settings.NoAccessUrl;
            }
            if (Settings.RequestErrors.UseServerSideRedirect)
                HttpContext.Current.Server.TransferRequest(str);
            else
                HttpContext.Current.Response.Redirect(str);
            return true;
        }
    }
1

I managed to resolve this thanks to John Rappel who helped out on Slack.

Whilst we had made this web config update to patch in our custom handler:

<httpHandlers>
 ...
  <add verb="*" path="sitecore_media.ashx" type="Custom.Sitecore.Extensions.CustomMediaRequestHandler , Custom.Sitecore.Extensions" />
...
</httpHandlers>

We were trying to patch it in as a pipeline as well and actually that isn't needed, it's only required as a handler. The required Pipeline is instead:

public class CustomExecuteRequest : Sitecore.Pipelines.HttpRequest.ExecuteRequest
    {
        protected override void PerformRedirect(string url)
        {
            if (Settings.RequestErrors.UseServerSideRedirect)
                HttpContext.Current.Server.TransferRequest(url);
            else
                WebUtil.Redirect(url, false);
        }
    }

Patched in like so:

<httpRequestBegin>
<processor type="Custom.Sitecore.Extensions.Pipelines.CustomExecuteRequest, Custom.Sitecore.Extensions" resolve="true" patch:instead="*[@type='Sitecore.Pipelines.HttpRequest.ExecuteRequest, Sitecore.Kernel']"/>
</httpRequestBegin>

This was due to some confusion over what was required here. This is now working in CD and CA.

John has a detailed post on this with a full solution for handling all 404s here which i'd recommend:

https://www.geekhive.com/buzz/post/2017/07/a-complete-guide-to-configuring-friendly-error-pages-in-sitecore-part-1-404-pages/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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