ASP.NET MVC to ignore “.html” at the end of all url

后端 未结 7 651
心在旅途
心在旅途 2021-01-04 18:52

I am new to asp.net mvc and now struggling with url routing. I\'m using asp.net mvc 3 RC2.

How can I create a url routing that IGNORES the very end

7条回答
  •  心在旅途
    2021-01-04 19:48

    You just need to tweak the default route in Global.asax.cs, try this:

    routes.MapRoute(
      "Default", // Route name
      "{controller}/{action}.{extension}/{id}", // URL with parameters
      new { controller = "Home", action = "Index", id = UrlParameter.Optional });
    

    The {extension} value from the url will be included in the route data, but you can just safely ignore it if you don't need it

提交回复
热议问题