Lysandus
Lysandus

Reputation: 764

Using .html with and MVC 4 app

I have a controller I made called test and going to website.com/test works just fine. How can I make that same controller respond if I try to go to website.com/test.html?

Upvotes: 1

Views: 78

Answers (2)

Blaise
Blaise

Reputation: 22242

RouteConfig.cs is the place to look at.

Solution 1: IgnoreRoute

In your RouteConfig.cs, under RegisterRoutes(RouteCollection routes):

  routes.IgnoreRoute("*.html");

Please make sure your IgnoreRoute statement is place ahead of all other MapRoute statement.

Solution 2: MapRoute

routes.MapRoute(
    name: "HtmlUrl",
    url: "{action}.html",
    defaults: new { controller = "Home"}
);

Upvotes: 1

Deblaton Jean-Philippe
Deblaton Jean-Philippe

Reputation: 11397

AttributeRouting for example can do that

Example :

 [GET("test")]
 [GET("test.html")]
 public ActionResult test()
 {
     return view();
 }

http://attributerouting.net/

Upvotes: 1

Related Questions