Kyle
Kyle

Reputation: 33701

MVC RouteConfig allow /Controller/Action.html

I have an MVC application and am using the standard routeconfig that routes /Controller/Action/Id

I want it to additionally capture /Controller/Action.html as the url and as well and point to /controller/action also.

I am using a jquery library that I have no control over, and a function requires a url that points to a webpage or an image. However, it doesn't appear to understand that ends without an extension(.html, .php etc) is a link to html and throws an error.

Edit: I tried as the commenter below suggested, and still can't seem to get it to work. Here is my route config.

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute("routeWithHtmlExtension",
            "{controller}/{action}.html",
            new { controller = "Home", action = "Index" }
        );

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

This Url works:

 http://localhost:14418/Album/Test

This one does not:

 http://localhost:14418/Album/Test.html

Upvotes: 1

Views: 2956

Answers (2)

Phonix
Phonix

Reputation: 2217

In web.config

<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
...
</system.webServer>

Upvotes: 2

George Stocker
George Stocker

Reputation: 57877

If you set up the following route, it will work:

routes.MapRoute("routeWithHtmlExtension",
    "{controller}/{action}.html",
    new {controller = "Home", action = "Index" }
);

Upvotes: 1

Related Questions