2015-11-12 66 views
4

我使用ASP.NET MVC開發了一個Web應用程序。我有路線問題。ASP.NET MVC路由不適用於.html擴展

我需要這樣的路線。 ​​

我定義一個路由,具體步驟如下

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

但路線是行不通的。 IIS向我展示404頁面。當我刪除.html擴展名,使路由起作用。

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

我該如何解決這個問題? 謝謝

回答

4

我已經將HtmlFileHandler添加到我的web.config。 .html路線現在可以工作。

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