[英]ASP.NET MVC Wild Card Controller any parameter routing
我想要控制器/動作,以便當我導航到:
mysite.com/whatever. i type here will pipe into...a ! string.
public ActionResult Index(string anything)
{
// anything = whatever. i type here will pipe into...a ! string.
return View();
}
我是否需要設置自定義路線?
我試過這個,但它似乎沒有處理時期等。
routes.MapRoute(
name: "Default",
url: "{*anything}",
defaults: new { controller = "Home", action = "Index" }
);
如果你用一個全能正則表達式限制你的路線:
routes.MapRoute(
"Default",
"{*anything}",
new { controller = "Home", action = "Index" },
new { anything = @"^(.*)?$" }
);
並確保您在web.config中設置了 UrlRoutingModule ,沒有先決條件確保即使是非托管請求(例如那些被認為具有擴展的請求)都通過路由模塊,您的catchall路由應該可以正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.