0

Default of asp.net-mvc4 is http://domainname.com/products/1 with routes

routes.MapRoute(
    name: "Products",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Products", action = "Index", id = UrlParameter.Optional }
);

and I want to rewrite to http://domainname.com/products/1.html that has .html extention . Any ideas for this?

John H
  • 14,422
  • 4
  • 41
  • 74
TienKenji
  • 63
  • 2
  • 5
  • 17

2 Answers2

0

Do you mean this:

routes.MapRoute(
    name: "Products",
    url: "{controller}/{action}/{id}.html",
    defaults: new { controller = "Products", action = "Index", id = UrlParameter.Optional }
);
Marthijn
  • 3,292
  • 2
  • 31
  • 48
0

Why would you want to put .html extension to a query string or route parameter?

if you take a website with html files, the extension is with the page not with the parameters. Don't know if you have any specific requirement to put it always at the end of the url. but it doesn't make any sense.

routes.MapRoute(
name: "Products",
url: "{controller}/{action}.html/{id}",
defaults: new { controller = "Products", action = "Index", id = UrlParameter.Optional }
);

you might have problems with iis after doing the above, please take a look at this discussion as well. ASP.NET MVC Routing - add .html extension to routes

Community
  • 1
  • 1
Amila
  • 3,711
  • 3
  • 26
  • 42