/// <summary>
 ///  Once a match is found and we have a Sitecore Item, we can send the response.
 /// </summary>
 private static void SendResponse(Item redirectToItem, string queryString, ResponseStatus responseStatus, HttpRequestArgs args)
 {
     var redirectToUrl = GetRedirectToItemUrl(redirectToItem);
     SendResponse(redirectToUrl, queryString, responseStatus, args);
 }
 private static void SendResponse(string redirectToUrl, string queryString, ResponseStatus responseStatusCode, HttpRequestArgs args)
 {
     args.Context.Response.Status = responseStatusCode.Status;
     args.Context.Response.StatusCode = responseStatusCode.StatusCode;
     args.Context.Response.AddHeader("Location", redirectToUrl + queryString);
     args.Context.Response.End();
 }
        private static ResponseStatus GetResponseStatus(Item redirectItem)
        {
            var result = new ResponseStatus
            {
                Status = "301 Moved Permanently",
                StatusCode = 301,
            };

            if (redirectItem != null)
            {
                var responseStatusCodeId = redirectItem.Fields[Constants.Fields.ResponseStatusCode];

                if (responseStatusCodeId != null && responseStatusCodeId.HasValue && !string.IsNullOrEmpty(responseStatusCodeId.ToString()))
                {
                    var responseStatusCodeItem = redirectItem.Database.GetItem(ID.Parse(responseStatusCodeId));

                    if (responseStatusCodeItem != null)
                    {
                        result.Status = responseStatusCodeItem.Name;
                        result.StatusCode = responseStatusCodeItem.GetIntegerFieldValue(Constants.Fields.StatusCode, result.StatusCode);
                    }
                }
            }

            return result;
        }