1

I have implemented Item resolver for item "quote" [home->quote] like http://sss.com/quote/Certquote/32 by implementing

 public class CustomItemResolverForQuote : HttpRequestProcessor
    { .... }

But when I change the language to Arabic (implementation similar to habitat language) it's retaining only till "quote" as that is the item in content and not the full path(of item resolver) "/certquote/32" is not retained like

http://sss.com/ar-sa/quote/

How do I retain the path after language change after implementing item resolver( for "quote") like http://sss.com/ar-sa/quote/Certquote/32

Any help is much appreciated

Thanking with Regards, Avinash

5
  • If you type sss.com/ar-sa/quote/Certquote/32, does it does the correct item in your browser ? Also with noting that the sitecore more you're operating on can cause some issues and confusion when you start working with custom item or language resolving. One easy way is to make sure you're cms logged in session is run in a private mode of your browser, or attach ?sc_mode=normal at the end of your URL. Nov 27, 2019 at 19:50
  • (please note that this is not the answer but since I cannot comment yet because of my points restriction, I am asking it here) Can you help share the code for "CustomItemResolverForQuote"? . Nov 28, 2019 at 13:04
  • the place where you are generating the link - sss.com/quote/Certquote/32 is broken, Share your cshtml code where you are generating the link var currentpage = Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Item); var certUrl = String.Empty; if (Sitecore.Context.Language != null && Sitecore.Context.Language.Name == "en") { certUrl = "/ar-sa" + currentpage; }else{ certUrl = "/en" + currentpage; }
    – Abhay Dhar
    Dec 3, 2019 at 7:16
  • @DebabrataBiswas var decodedUrl = HttpUtility.UrlDecode(requestUri); if (Regex.IsMatch(decodedUrl, Constants.ItemResolver.pattern, RegexOptions.Multiline)) { var startItem = Context.Site.StartPath; var match = Regex.Match(decodedUrl, Constants.ItemResolver.pattern, RegexOptions.Multiline); var groupCollection = match.Groups.Cast<Group>().Where(x => x.Value != decodedUrl).ToList(); Item currentItem = null; foreach (var group in groupCollection) //get the item path
    – Avinash J
    Dec 5, 2019 at 17:26
  • @AbhayDhar no the code is written in Itemresolver
    – Avinash J
    Dec 5, 2019 at 18:19

1 Answer 1

1

From what i have understood from your requirements, I wrote the following class that works for any languages. Hope it helps.

public class ItemResolver: HttpRequestProcessor
{
    public override void Process(HttpRequestArgs args)
    {
        try
        {
            string pattern = "/Certquote/32";//should be defined as a constant

            if (Sitecore.Context.Item == null)
            {
                string originalRequest = Sitecore.Context.RawUrl;
                string itemPath = args.Url.ItemPath;

                var decodedUrl = HttpUtility.UrlDecode(originalRequest);
                if (Regex.IsMatch(decodedUrl, pattern, RegexOptions.Multiline))
                {
                    var match = Regex.Match(decodedUrl, pattern, RegexOptions.Multiline);

                    itemPath = itemPath.ToLower().Split(new string[] { match.Value.ToLower() }, StringSplitOptions.RemoveEmptyEntries)[0];
                    itemPath = itemPath.Replace("-"," ");
                    Sitecore.Context.Item = Sitecore.Context.Database.GetItem(itemPath, Sitecore.Context.Language);
                }
            }

        }
        catch (Exception ex)
        {
        }
    }
}

Thanks

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.