14
我正在嘗試將所有與現有控制器不匹配的url重定向到某個控制器。沒有控制器或操作名稱的Asp.net mvc路由
例如,URL mywebsite.com/newyork應該被處理爲mywebsite.com/Cities/Info/newyork
我使用下面的代碼在我的RegisterRoutes,但它似乎並沒有因爲我的工作得到404的回覆:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Cities",
url: "{cityname}",
defaults: new { controller = "Cities", action = "Info", cityname= "" }
);