Asp.net mvc MVC路由-通配符URL,但受约束
我基本上想这样做:Asp.net mvc MVC路由-通配符URL,但受约束,asp.net-mvc,asp.net-mvc-routing,Asp.net Mvc,Asp.net Mvc Routing,我基本上想这样做: routes.MapRoute( "Pass-through", "/api/{*url}", new { controller = "PassThrough", action = "PassThroughToApi" }); 我将请求发送给的控制器有: public ContentResult PassThroughToApi(string url = null) 但是,我希望能够同时约束URL。例如: routes.MapRoute( "Pass-th
routes.MapRoute(
"Pass-through",
"/api/{*url}",
new { controller = "PassThrough", action = "PassThroughToApi" });
我将请求发送给的控制器有:
public ContentResult PassThroughToApi(string url = null)
但是,我希望能够同时约束URL。例如:
routes.MapRoute(
"Pass-through",
"/api/v1/some/specific/address/{whatever}/{parameters}",
new { controller = "PassThrough", action = "PassThroughToApi" });
但我仍然希望控制器将请求的URL作为变量获取,我不关心获取实际参数,只要URL与模式匹配。或者我应该从另一个地方(比如上下文)获取请求的URL,而不是作为参数传递给它吗?您可以创建
并将其分配给直通
路线
routes.MapRoute(
"Pass-through",
"/api/{*url}",
new { controller = "PassThrough", action = "PassThroughToApi" },
new { apiRedirect = new ApiRedirectingConstraint("/api/v1/some/specific/address/{whatever}/{parameters}") }
);
我需要能够在路由引导中指定路由(约束),例如在
routes.maprote
。我想知道,是否可以将实际约束URL作为参数传递给apirectionconstraint
ctor@HristoYankov有帮助吗?或者你需要别的什么?
routes.MapRoute(
"Pass-through",
"/api/{*url}",
new { controller = "PassThrough", action = "PassThroughToApi" },
new { apiRedirect = new ApiRedirectingConstraint("/api/v1/some/specific/address/{whatever}/{parameters}") }
);