Josh
Josh

Reputation: 8477

ASP.NET MVC URL Routing or URL rewriting

I'm new to ASP.NET MVC and trying to determine the best approach for the following task. I have the following URLs that carry over from Web Forms application, that I want to continue to function by returning following paths in MVC:

  1. http://example.com/Default.aspx -> http://example.com/
  2. http://example.com/about.aspx -> http://example.com/about
  3. http://example.com/keyword1-keyword2-contact.aspx -> http://example.com/contact

Should I create a new Map Route or use URL Rewrite module? Please provide an example for the approach you advocate. The application is hosted in IIS 7.5 and uses ASP.NET 4.5 and MVC 4.0.

Upvotes: 1

Views: 2431

Answers (1)

Ernestas Stankevičius
Ernestas Stankevičius

Reputation: 2493

I'm new too, but I will try to help you.

In App_Start/RouteConfig.cs

1

routes.MapRoute(
   null,
   "Default.aspx",
   defaults: new { controller = "Default", action = "Index"},
);

2

routes.MapRoute(
   null,
   "about.aspx",
   defaults: new { controller = "Default", action = "About"},
);

3

routes.MapRoute(
   null,
   "{keyword1}-{keyword2}-contact.aspx",
   defaults: new { controller = "Default", action = "Contact"},
);

Upvotes: 1

Related Questions