4

I'm working on a redirect url feature and have added a pipeline processor after the ItemResolver.

However the value of HttpContext.Current.Request.Url.LocalPath equals "/layouts/system/VisitorIdentificationCSS.aspx" rather than the value typed in the address bar. If I patch before the ItemResolver it works.

If I disable @Html.Sitecore().VisitorIdentification() from my view the pipeline is never hit for as long as it's after ItemResolver.

Any idea what this relates to? I'm not sure if it relates to the license not including xDB

public override void Process(HttpRequestArgs args) 
{ 
    if (args.Context.Request.Url.OriginalString.ToLower().Contains(‌​"/sitecore")) 
        return; 

    if (Sitecore.Context.Item == null) 
        var path = HttpContext.Current.Request.Url.LocalPath;

}
2
  • Can you share code of your processor?
    – Marek Musielak
    Commented Mar 7, 2017 at 8:50
  • I've stripped it right down to something very simple and the variable 'path' is the problematic one. Pretty odd one this: public override void Process(HttpRequestArgs args) { if (args.Context.Request.Url.OriginalString.ToLower().Contains("/sitecore")) return; if (Sitecore.Context.Item == null) var path = HttpContext.Current.Request.Url.LocalPath; }
    – NS31
    Commented Mar 7, 2017 at 8:54

1 Answer 1

5

Problem is with:

if (Sitecore.Context.Item == null)

in your code.

After ItemResolver is executed, that will be never null for Sitecore items.

That's why you only see this hit for VisitorIdentification.

If you want your code to be executed when Sitecore "page" is loaded, change your code to

if (Sitecore.Context.Item != null)
{
    ...
}
1
  • Just an update, I did want to use context.item == null because I only want to be able to setup redirects for items that don't already exist in Sitecore. Strangely enough it started working once I made a call to an item before attempting to get the LocalPath. Odd one really not sure what caused it to return VisitorIdentification in the first pace
    – NS31
    Commented Mar 7, 2017 at 15:29

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.