1

I am using sitecore 10.3 jss with sxa site. I got error while updating the general link field and save in wesite in arabic version
enter image description here

The last thing I did on the instance is deploying the below redirect processor and when I disable it, the error not come but I did not get what is the wrong with the code

using System;
using System.Linq;
using System.Web;
using Sitecore.Data.Managers;
using Sitecore.Diagnostics;
using Sitecore.Pipelines.HttpRequest;

namespace Murabba.Foundation.LanguageRedirect
{
    public class LanguageRedirectProcessor : HttpRequestProcessor
    {
        public override void Process(HttpRequestArgs args)
        {

            Assert.ArgumentNotNull(args, "args");
            //make sure you are in the right context, and that the pipeline hasn't resolved an item yet
            if (args.HttpContext.Request.RawUrl != null
                && Sitecore.Context.Item != null && Sitecore.Context.Database != null
                && Sitecore.Context.Database.Name != "core"
                && !args.HttpContext.Request.RawUrl.StartsWith("/sitecore", StringComparison.OrdinalIgnoreCase)
                && !args.HttpContext.Request.RawUrl.StartsWith("/api", StringComparison.OrdinalIgnoreCase)
                && !args.HttpContext.Request.RawUrl.StartsWith("/jss", StringComparison.OrdinalIgnoreCase)
                && !args.HttpContext.Request.RawUrl.StartsWith("/_next", StringComparison.OrdinalIgnoreCase)
                && !args.HttpContext.Request.RawUrl.StartsWith("/-/jssmedia", StringComparison.OrdinalIgnoreCase))
            {
                if (!args.HttpContext.Request.RawUrl.StartsWith($"/{Sitecore.Context.Language.Name}"))
                {
                    HttpContext.Current.Response.Redirect($"/{Sitecore.Context.Language.Name}{args.HttpContext.Request.RawUrl}/");
                }
                else if (!args.HttpContext.Request.RawUrl.EndsWith($"/"))
                {
                    HttpContext.Current.Response.Redirect($"{args.HttpContext.Request.RawUrl}/");
                }
                else
                {
                    return;
                }
            }
          
        }
    }
}



<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <httpRequestBegin>
        <processor type="Murabba.Foundation.LanguageRedirect.LanguageRedirectProcessor, Murabba.Foundation.LanguageRedirect" patch:before="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/>
      </httpRequestBegin>
    </pipelines>
  </sitecore>
</configuration>

any ideas how to configure what is the issue??

1 Answer 1

0

This issue is happening because there are other url's apart from the above you added that are requested on Content Authoring environment, that in-turn will execute the custom logic you added for redirection.

One of those urls is /-/item/v1 that is generated when you edit the General Link. In this case it will go inside the redirection logic and set the context language of shell site inside Content Authoring environment to Arabic language, since you are appending language code in the redirection.

Therefore you should always enable custom logic in which redirection is happening through language code, in the Content Delivery server only. This can be enabled by adding role based configuration as below on the redirection processor.

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
  <sitecore role:require="ContentDelivery">
    <pipelines>
      <httpRequestBegin>
        <processor type="Murabba.Foundation.LanguageRedirect.LanguageRedirectProcessor, Murabba.Foundation.LanguageRedirect" patch:before="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/>
      </httpRequestBegin>
    </pipelines>
  </sitecore>
</configuration>

Using above configuration changes, the above redirection logic will not be executed on Content Authoring environment, hence the context language of shell site will not change and the issue you are getting will also not occur.

Hope this helps!!!

Your Answer

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

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