Exemple #1
0
        public void ExecuteRequest(IMiddlerContext middlerContext, IActionHelper actionHelper)
        {
            var rewriteTo  = actionHelper.BuildPathFromRoutData(Parameters.RewriteTo);
            var isAbsolute = Uri.IsWellFormedUriString(rewriteTo, UriKind.Absolute);

            if (isAbsolute)
            {
                middlerContext.Request.Uri = new Uri(rewriteTo);
            }
            else
            {
                var builder = new UriBuilder(middlerContext.Request.Uri);
                builder.Query = null;
                if (rewriteTo.Contains("?"))
                {
                    builder.Path  = rewriteTo.Split("?")[0];
                    builder.Query = rewriteTo.Split("?")[1];
                }
                else
                {
                    builder.Path = rewriteTo;
                }


                middlerContext.Request.Uri = builder.Uri;
            }



            //middlerContext.ForwardBody();

            //var nUrl = new UriBuilder(Parameters.RewriteTo);
            //builder.Path = Parameters.RewriteTo;
        }
        public void ExecuteRequest(IMiddlerContext middlerContext, IActionHelper actionHelper)
        {
            var uri = new Uri(actionHelper.BuildPathFromRoutData(Parameters.RedirectTo));

            if (Parameters.PreserveMethod)
            {
                middlerContext.Response.StatusCode = Parameters.Permanent ? StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect;
            }
            else
            {
                middlerContext.Response.StatusCode = Parameters.Permanent ? StatusCodes.Status301MovedPermanently : StatusCodes.Status302Found;
            }

            middlerContext.Response.Headers["Location"] = uri.AbsoluteUri;
        }