Saving query string parameters using RouteMagic MVC

Is there a way to save the query string parameter or all of them with redirection using RouteMagic MVC? Do I need an old url: LegacyPage.aspx? Q = value to redirect to New / NewAction? Q = value . The example below gives me a strange result: New / NewAction? Q = q , not the actual value of the query string. I tried all kinds of permutations without any luck. Any help would be appreciated.

var newRoute = routes.MapRoute( "New", "New", new { controller = "New", action = "NewAction"} ); routes.Redirect(r => r.MapRoute("Legacy", "LegacyPage.aspx"), true) .To(newRoute); 
+4
source share
1 answer

I also wanted the query string parameters to be moved to the destination URL. But I can’t even get your situation. I am using version 1.2 of routeMagic. I looked at the source code:

 public IHttpHandler GetHttpHandler(RequestContext requestContext) { var requestRouteValues = requestContext.RouteData.Values; var routeValues = AdditionalRouteValues.Merge(requestRouteValues); var vpd = TargetRoute.GetVirtualPath(requestContext, routeValues); string targetUrl = null; if (vpd != null) { targetUrl = "~/" + vpd.VirtualPath; return new RedirectHttpHandler(targetUrl, Permanent, isReusable: false); } return new DelegateHttpHandler( httpContext => httpContext.Response.StatusCode = 404, false); } 

And it doesn't seem like query string parameters are being added to targeUrl.

0
source

Source: https://habr.com/ru/post/1396548/


All Articles