开发者

MVC Routing: How to route /mypath/Default.aspx to /Default.aspx and keep QueryString?

We upgraded our solution to MVC 2. Outside links are still using /mypath/Default.aspx with a query string of n=10. Is the开发者_如何学JAVAre 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.


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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜