1

We upgraded our solution to MVC 2. Outside links are still using /mypath/Default.aspx with a query string of n=10. Is there any way to catch that route with a controller and call a Default.aspx file with the proper query string?

We tried simply rerouting with IIS6 as well as a meta refresh, but both strip off the query string.

Nick Craver's answer looks promising as an answer to this question.

Community
  • 1
  • 1
Zachary Scott
  • 20,968
  • 35
  • 123
  • 205

1 Answers1

1

I'm not sure what you mean by "and call a Default.aspx file with the proper query string?" but if you mean to call your default route, then it can easily be done.

You should be able to just specify a route on "mypath/Default.aspx". The querystring will be automatically bound to your method.

For example:

routes.MapRoute(
    "LegacyUrl", // Route name
    "mypath/Default.aspx", // URL with parameters
    new { controller = "Home", action = "Index"} 
);

Then your method:

[HttpGet]
public ActionResult Index(int n)
{
    // do something with n, maybe pass it to the View
    return View();
}
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • Will `routes.MapPageRoute("/old/path/to/myWebForm.aspx", "{*value}", "~/myWebForm.aspx");` forward the QueryString parameters or Posted data to the new page, e.g., /old/path/to/myWebForm.aspx?somedata=yep&otherdata=yep become /myWebForm.aspx/?somedata=yep&otherdata=yep? If this is true only in some cases, how could you get it to forward the data in all cases? – Zachary Scott Jan 10 '11 at 04:48