Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Route Doesn't Work With .html Extension

I develop a web application with ASP.NET MVC. I have problem with route.

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

I've defined a route for this as follows

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

But the route doesn't work. IIS is showing me 404 page. When i remove .html extension so 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

like image 452
Yargicx Avatar asked Nov 12 '15 22:11

Yargicx


1 Answers

I've added HtmlFileHandler to my web.config. And .html routes work now.

<handlers>
  <add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>    
like image 100
Yargicx Avatar answered Sep 20 '22 01:09

Yargicx