What is the way to get part of the URL path in Sitecore?

I am writing an HTTPRequest pipeline HTTPRequest to redirect inbound requests where Sitecore can find the item you HTTPRequest , but where the requested URL is not generated exactly like Sitecore. This should prevent problems with duplicate content on the Internet.

The part of the URL that I want to learn is the part that will match the result of LinkManager.GetItemUrl(context.item) . In our case, we have a language embedded in the path, for example:

 www.mysite.com/en-gb/stuff/things 

So GetItemUrl returns /en-gb/stuff/things

I cannot find the correct method, either on the Sitecore.Pipelines.HttpRequest.HttpRequestArgs object, or on the System.Web.HttpContext.Current.Request.Url object.

I can get the whole URL or path minus the language injection. What object.method will give me /en-gb/stuff/things ?

+4
source share
2 answers

I'm not sure if you understood correctly, but it looks like you are looking for System.Web.HttpContext.Current.Request.RawUrl . If not, please explain what you want to achieve in more detail.

+5
source

This is not a direct answer, but it can be useful, though, as Sitecore throws a couple of tricks into the mix, doing what (I think) you want to achieve.

From memory...

The language portion of the URL is removed by the strip language pipeline processor if (and only if) the linkmanager is installed with LanguageEmbedding 'always' or 'asNeeded'. If it is set to never, if it does nothing for the URL in HttpRequest. This can go wrong with your path comparison if you compare a pathless path with the path prefix from LinkManager.

You can add a pipeline step to the stripLanguage step, which adds the incoming URL as you want to the dictionary in HttpRequest.

 public class StoreOriginalRequestUrl : PreprocessRequestProcessor { public override void Process(PreprocessRequestArgs args) { args.Context.Items["OriginalRequestUrl"] = args.Context.Request.RawUrl; } } 

... you can select this at a later stage after the element recognizer. I assume this is what you are doing - comparing the request URL to the context URL from Linkmanager.

I think you can parse themanmanager link, which returns the Url string as a Uri object and compare the path there. It seems to work better when you use the full URL, so maybe change the UrlOptions returned from GetDefaultOptions () to provide it.

Floor

+2
source

All Articles