Ian Vink
Ian Vink

Reputation: 68750

Using an MVC Route for an old page.aspx?

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?

Upvotes: 3

Views: 3902

Answers (2)

Rinat Galyautdinov
Rinat Galyautdinov

Reputation: 255

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.

Upvotes: 0

afzalulh
afzalulh

Reputation: 7943

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

Upvotes: 6

Related Questions