1

With Sitecore 8.2 MVC, what is the best way to intercept query string parameters from external sources site wide?

For example, another site will link into our Sitecore site with a URL that may contain several query string parameters. We intercept and interpret these query string parameters to determine where to route them within the site.

This behavior needs to happen no matter what initial page within the site is requested.

1
  • 2
    Consider creating some redirect rules, either using the IIS Rewrite module or a Sitecore Redirect module if you want to keep them configurable from the CMS.
    – jammykam
    Commented Jan 10, 2018 at 23:15

1 Answer 1

1

You could probably place logic to handle this in a custom pipeline that runs before it resolves the item, which can parse the values of the Querystring and redirect to the appropriate page. An example of what I mean is below:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
   <sitecore>
      <pipelines>
         <httpRequestBegin>
            <processor patch:before="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']" type="Example.Components.Pipelines.ProcessPathResolver, Example.Components" />
         </httpRequestBegin>
      </pipelines>
   </sitecore>
</configuration>

Then in your ProcessPathResolver you could have code like this:

namespace Example.Components.Pipelines
{
    public class ProcessPathResolver : HttpRequestProcessor
    {
        public override void Process(HttpRequestArgs args)
        {
            if (Sitecore.Context.Site.Name.ToLowerInvariant() == "shell" || args.Url.FilePath.Trim('/').ToLower().StartsWith("sitecore"))
                return;

            string requestUrl = args.Url.ItemPath;
            string localPath = args.LocalPath;
            var queryString = args.Context.Request.QueryString;

            // Process the querystring parameters and redirect the user to the correct path

        }
    }
}

This new resolver would run before your items are resolved in the ItemResolver, and redirect to the correct page.

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.