ASP.NET MVC route does not work with .html extension

I am developing a web application with ASP.NET MVC. I have a problem with the route.

I need such a route. http: //localhost/content-name/23.html

I defined a route for this as follows

//i need this route but it not work
routes.MapRoute(
"GetContent",
"{sefLink}/{contentId}.html",
new { controller = "Content", action = "GetContent" },
new[] { "CanEcomm.Controllers" });

But the route does not work. IIS shows me 404 pages. When I remove the .html extension so that the route works.

//this route is working. i just remove ".html" extension
routes.MapRoute(
    "GetContent",
    "{sefLink}/{contentId}",
    new { controller = "Content", action = "GetContent" },
    new[] { "CanEcomm.Controllers" });

How can i solve this? thank you

+4
source share
1 answer

I added HtmlFileHandler to my web.config. Now the .html routes are executed.

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

Source: https://habr.com/ru/post/1615658/


All Articles