我有一個控制器,我叫做test
,去website.com/test
工作得很好。如果我嘗試去website.com/test.html
,如何讓同一控制器響應?使用.html和MVC 4應用
1
A
回答
1
AttributeRouting例如可以做到這一點
實施例:
[GET("test")]
[GET("test.html")]
public ActionResult test()
{
return view();
}
+0
這對我有效。 – Lysandus
1
RouteConfig.cs
是看的地方。
解決方案1:IgnoreRoute
在你RouteConfig.cs
,RegisterRoutes(RouteCollection routes)
下:
routes.IgnoreRoute("*.html");
請確保您的IgnoreRoute
說法是領先於所有其他MapRoute
聲明的地方。
解決方案2:MapRoute
routes.MapRoute(
name: "HtmlUrl",
url: "{action}.html",
defaults: new { controller = "Home"}
);
相關問題
- 1. 用HTML解析HTML到iTextSharp和MVC 4
- 2. 在MVC 4應用
- 3. 使用MVC 4將HTML轉換爲PDF
- 4. 如何在MVC 4中使用HTML錨?
- 5. 混合asp.net 4和MVC應用程序
- 6. 使用Spring MVC和html
- 7. 使用ASP.NET MVC 4和Angularjs的異步Web應用程序
- 8. 允許在MVC 4中使用一些html標籤4
- 9. 使用TagBuilder和ASP.NET MVC 4(使用Razor引擎)呈現html代碼
- 10. 使用Mono和MVC 4查看錯誤
- 11. .net mvc 4使用剃刀和json
- 12. 使用flex 4(MATE MVC)和MSMQ集成
- 13. Roles.IsUserInRole()使用的wsHttpBinding和MVC 4
- 14. MVC 4授權和登錄使用
- 15. 無法使用html助手添加html屬性 - MVC 4
- 16. MVC 4應用,EF和Web API結構和用戶認證
- 17. 在asp.net mvc應用程序中使用HTML和CSS
- 18. 如何使用MVC 4
- 19. MVC 4 - 使用兩張表
- 20. 使用MVC 4的Web API
- 21. ModelFactory爲MVC 4使用Unity
- 22. 使用Application API與MVC 4
- 23. Spring MVC使用.html
- 24. 使用Spring MVC和Html圖像上傳
- 25. 在mvc 4和mvc 5中使用IController有什麼區別?
- 26. 在Flex 4中使用HTML?
- 27. MVC 4和autofac:DependencyResolutionException
- 28. MVC 4和RenderPartial
- 29. MVC 4和JavaScript
- 30. HTML編碼與TextBoxFor MVC 4
http://weblogs.asp.net/jgalloway/archive/2013/08/29/asp-net-mvc-routing-intercepting-file-requests-like- index-html-and-what-it-teachhes-about-how-routing-works.aspx –