3

We recently analyzed the Google crawling errors on our production system. We noticed a weird 500 Code for URLs http://localSitecore/hu and http://localSitecore/se.

So we tried to figure out where it came from, and eventually found out that it is already mapped in vanilla Sitecore. We tested 8.1 Update 2, 8.2 Initial Release and 8.2 Update 2. They all have that mapping.

How can we get rid of the mapping? Where is it coming from?

The error that is thrown is,

The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type 'Example.GlassMapper.sitecore.templates.Example.Pages.IContentPageModel'.
8

This is Sitecore's default language mapping. It recognizes hu as Hungarian and se as Swedish.

Happens in the StripLanguage processor in the <preprocessRequest> pipeline. If you never need language embedding in the URL, you can disable it. Alternatively, define languageEmbedding to be never as options on your LinkManager.

Edited to add.

There's also a setting that forces the hand of this processor, regardless of your LinkManager setting. Set it to false, to disable the preprocessor.

<!--  LANGUAGES ALWAYS STRIP LANGUAGE
        This setting specifies if the StripLanguage processor in the <preprocessRequest> pipeline will parse and remove languages from
        the URL, even when the languageEmbedding attribute of the linkProvider is set to "never". You should only change this setting 
        to "false" if the default behavior causes problems in your solution.
        Default value: true 
  -->
<setting name="Languages.AlwaysStripLanguage" value="true" />
  • Thanks. But why only for "hu" and "se"? There should be a few more mappings for languages then. – z00mable Mar 14 '17 at 9:08
  • In theory there could be quite many, yes. But the Google bot wouldn't try them unless someone "told" it, the URL existed. So somehow, it must have sniffed that "/hu" could be a valid option and then tries to visit it. I would probably try and work out why the site 500s when serving Hungarian, and make it return 404 as it is really supposed to. That should make Google forget about it, in time. – Mark Cassidy Mar 14 '17 at 9:14
1

Regarding the thrown error. Mike Edwards pointed out the underlying issue:

There is an issue with the view rendering pipeline where Glass will return null for a missing language, but Sitecore returns an object. Causing the Dictionary Error.

Activate the excluded config z.Glass.Mapper.Sc.ViewRender.config.exclude

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <mvc.getRenderer>
        <processor type="Sitecore.Mvc.Pipelines.Response.GetRenderer.GetViewRenderer, Sitecore.Mvc">
          <patch:attribute name="type">
            Glass.Mapper.Sc.Mvc.Pipelines.Response.GetRenderer.GetViewRendererWithItemValidation, Glass.Mapper.Sc.Mvc
          </patch:attribute>
        </processor>
      </mvc.getRenderer>
    </pipelines>
  </sitecore>
</configuration>

Use this class to override this behavior: https://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc.Mvc/Pipelines/Response/GetRenderer/GetViewRenderWithItemValidation.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sitecore.Mvc.Extensions;
using Sitecore.Mvc.Pipelines.Response.GetRenderer;
using Sitecore.Mvc.Presentation;

namespace Glass.Mapper.Sc.Mvc.Pipelines.Response.GetRenderer
{
    /// <summary>
    /// This class overrides Sitecores default view rendering. Sitecore by default will return a RenderingItem even
    /// it the target item does not exist.
    /// </summary>
    public class GetViewRendererWithItemValidation : GetViewRenderer
    {
        protected override Renderer GetRenderer(Rendering rendering, GetRendererArgs args)
        {
            var viewRenderer = base.GetRenderer(rendering, args) as ViewRenderer;
            if (viewRenderer == null)
                return null;

            // Ignore item check when in page editor
            if (Utilities.IsPageEditor || Utilities.IsPageEditorEditing)
                return viewRenderer;

            // Override renderer to null when there is an unpublished item refererenced by underlying view
            return viewRenderer.Rendering.Item != null && viewRenderer.Rendering.RenderingItem.ValueOrDefault(i => i.InnerItem) != null
                ? viewRenderer
                : null;
        }
    }
}
  • Can you copy the code for the class here, please? – Zachary Kniebel Mar 14 '17 at 20:55

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.