Bala Murugan A.S
Bala Murugan A.S

Reputation: 21

Asp.net mvc routing - how to allow .html extension in mvc routing

Controller Name is : TestController

Action Name is :HtmlContent

and Url : localhost:53907/en_US/Index.html

I would like to call HtmlContent action from TestController if url which contains .html extension.

I have placed breakpoint in HtmlContent but its not hitting if i enter url like mentioned above,

routes.MapRoute(
    name: "MyCustomRoute",
    url: "en_US/{pagename}",
    defaults: new { controller = "Test", action = "HtmlContent" },
    constraints: new {pagename = @".*?$(?<=\.html)" }
);

How to write routing for this requirement?

Upvotes: 0

Views: 2312

Answers (1)

Manish Singh
Manish Singh

Reputation: 1004

routes.MapRoute(
    name: "MyCustomRoute",
    url: "en_US/{pagename}.html",
    defaults: new { controller = "Test", action = "HtmlContent" },
    constraints: new {pagename = @".*?$(?<=\.html)" }
);

and add code on web.config

<add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

its work for me if any query .please comment

Upvotes: 1

Related Questions