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.

  • 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 Jan 10 '18 at 23:15
0

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.