0

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) its 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

  • 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. – Vincent Lui Nov 27 '19 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"? . – Debabrata Biswas Nov 28 '19 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 '19 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 '19 at 17:26
  • @AbhayDhar no the code is written in Itemresolver – Avinash J Dec 5 '19 at 18:19
0

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

| improve this answer | |

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.