Esempio n. 1
0
        public new IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            //run the onredirection action. For example, this can be used to log that the redirection ocurred,
            //or add additional route data at redirection-time.
            if (OnRedirectAction != null)
            {
                OnRedirectAction(requestContext, this);
            }

            var requestRouteValues = requestContext.RouteData.Values;

            var routeValues = AdditionalRouteValues.Merge(requestRouteValues);

            var vpd = TargetRoute.GetVirtualPath(requestContext, routeValues);

            if (vpd != null)
            {
                string targetUrl = "~/" + vpd.VirtualPath;

                //add query strings
                var qsHelper    = requestContext.HttpContext.Request.QueryString;
                var queryString = String.Join("&", qsHelper.AllKeys.Select(i => HttpUtility.UrlEncode(i) + "=" + HttpUtility.UrlEncode(qsHelper[i])));
                if (!string.IsNullOrWhiteSpace(queryString))
                {
                    targetUrl += "?" + queryString;
                }

                return(new RedirectHttpHandler(targetUrl, Permanent, isReusable: false));
            }
            return(new DelegateHttpHandler(rc => rc.HttpContext.Response.StatusCode = 404, requestContext.RouteData, false));
        }
Esempio n. 2
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            //run the onredirection action. For example, this can be used to log that the redirection ocurred.
            if (OnRedirectAction != null)
            {
                OnRedirectAction(requestContext, this);
            }

            var requestRouteValues = requestContext.RouteData.Values;

            var mergedRouteValues = AdditionalRouteValues != null?AdditionalRouteValues.Merge(requestRouteValues) : new RouteValueDictionary();

            var vpd = TargetRoute.GetVirtualPath(requestContext, mergedRouteValues);

            if (vpd != null)
            {
                string targetUrl = "~/" + vpd.VirtualPath;

                //add query strings
                var qsHelper = requestContext.HttpContext.Request.QueryString;
                if (qsHelper != null)
                {
                    var queryString = String.Join("&", qsHelper.AllKeys.Select(key => key + "=" + qsHelper[key]));
                    if (!string.IsNullOrWhiteSpace(queryString))
                    {
                        targetUrl += "?" + queryString;
                    }
                }

                return(new RedirectHttpHandler(targetUrl, Permanent, isReusable: false));
            }
            return(new DelegateHttpHandler(rc => rc.HttpContext.Response.StatusCode = 404, requestContext.RouteData, false));
        }
Esempio n. 3
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var requestRouteValues = requestContext.RouteData.Values;
            var routeValues        = AdditionalRouteValues.Merge(requestRouteValues);
            var vpd = TargetRoute.GetVirtualPath(requestContext, routeValues);

            if (vpd == null)
            {
                return(new DelegateHttpHandler(rc => rc.HttpContext.Response.StatusCode = 404, requestContext.RouteData, false));
            }

            var targetUrl = "~/" + vpd.VirtualPath;

            if (!IncludeQueryStringInRedirect)
            {
                return(new RedirectHttpHandler(targetUrl, Permanent, isReusable: false));
            }

            var qs          = new StringBuilder("?");
            var queryString = requestContext.HttpContext.Request.QueryString;

            foreach (var key in queryString.AllKeys.Where(key => !requestRouteValues.ContainsKey(key)))
            {
                qs.AppendFormat("{0}={1}&", key, queryString[key]);
            }

            targetUrl += qs.ToString(0, qs.Length - 1);

            return(new RedirectHttpHandler(targetUrl, Permanent, isReusable: false));
        }
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var requestRouteValues = requestContext.RouteData.Values;

            var routeValues = requestRouteValues.Merge(AdditionalRouteValuesFunc(requestContext));

            var vpd = TargetRoute.GetVirtualPath(requestContext, routeValues);

            if (vpd != null)
            {
                string targetUrl = "~/" + vpd.VirtualPath;
                return(new RedirectHttpHandler(targetUrl, Permanent, false));
            }
            return(new DelegateHttpHandler(rc => rc.HttpContext.Response.StatusCode = 404, requestContext.RouteData, false));
        }