我有一个我做的控制器叫做test
,去website.com/test
工作得很好。如果我尝试转到website.com/test.html
,如何使同一控制器响应?
例如
AttributeRouting 可以做到这一点
例:
[GET("test")]
[GET("test.html")]
public ActionResult test()
{
return view();
}
http://attributerouting.net/
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"}
);