Skip to main content
2 of 3
added 173 characters in body
ckhanna
  • 3.7k
  • 1
  • 1
  • 12

Strip language is set inside the preprocessRequest pipeline which runs before the httpRequestBegin pipeline in which site context is set. Hence in order to obtain site context inside the custom processor created in the preprocessRequest pipeline using below code snippet.

using Sitecore.Pipelines.PreprocessRequest;
using Sitecore.Sites;
using Sitecore.Web;
using System.Linq;

public class CustomStripLanguage : StripLanguage
{
  public override void Process(PreprocessRequestArgs args)
  {
     var hostName = args.HttpContext.Request.Url.Host;
     SiteInfo site = SiteContextFactory.Sites
                .Where(s => s.RootPath != "" & s.HostName.Contains(hostName))
                .FirstOrDefault();
     if(site != null)
     {
        SiteContext contextSite =  SiteContextFactory.GetSiteContext(site.Name);
        // Based on the site context you can decide whether to strip language or not
        if(contextSite.Properties["StripLanguage"] == "false"){
           return;
        }
     }
     base.Process(args);
   }
}

Using above way, you should be successfully able to fetch site name inside preprocessRequest pipeline and decide whether the language should be stripped for the particular site through reading StripLanguage property on the site context .

Hope this helps!!! Let me know in case you face any issues.

ckhanna
  • 3.7k
  • 1
  • 1
  • 12