The Proper Way Of Handling Redirects In Sitecore CMS

The natural path an ASP.NET developer would take to make server-side redirects is to use the HTTP Response object.


Using the above code within a Sitecore CMS layout or sublayout will work fine. But if you tried to use the above code in a module that binds to the HttpRequestBegin pipeline. You will run into issues. The first issue you will encounter is Sitecore complaining about you terminating the request before Sitecore has finished with processing all its pipeline events.So the natural thing to do is remove the code that causes it to end the response ‘HttpContext.Current.Response.End()‘. This will work fine as long as you do not have any other custom modules attached to the HttpRequestBegin pipeline event.

If you do, you are subject to the other custom modules in the HttpRequestBegin pipeline event overwriting your redirect command, resulting in the default Sitecore ItemResolver taking over the request. Which would return a 404 if the item does not exist or returns the item if it exists. But the point of the story is; your redirect no longer works.

To avoid both of these issues, use the Sitecore provided redirect method found in the Sitecore.Web.WebUtil namespace.


Leave a Reply

Your email address will not be published. Required fields are marked *