我有一个我打电话的控制器,test并且可以website.com/test正常工作。如果我尝试去,如何让同一个控制器响应website.com/test.html?
2 回答
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"}
);
于 2013-09-27T22:22:19.820 回答
1
例如 AttributeRouting 可以做到这一点
例子 :
[GET("test")]
[GET("test.html")]
public ActionResult test()
{
return view();
}
于 2013-09-27T19:15:42.583 回答