We are re-writing an old asp.net site into MVC4.
There are many links to our site that look like this (that we don't control but must support):
www.some.com/page.aspx?id=5
Is there a way to get a request for /page.aspx?id=5 into a Route so that we can handle the request, pass it to a controller/action and then handle it from there?
In the RouteConfig, add a route (before default route):
routes.MapRoute(
name: "DefaultAspx",
url: "page.aspx",
defaults: new { controller = "MyAspxPage", action = "Index", id = UrlParameter.Optional }
);
In the controller catch the page id:
(MyAspxPageController)
public ActionResult Index(int id)
{
// Do whatever needed
//return View();
}
Check out, you might also introduce "areas" to your app - it's helpful if your project is big enough. And if you use them, they will reflect on your routes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.