我想弄清楚 UrlReferrer
的路由值是什么在 Controller Action 中。
我无法弄清楚传入 URL 在 MVC 管道的哪个部分被转换为 RouteValues,我想要实现的目标接近于此。
最佳答案
您需要调用RouteTable.Routes.GetRouteData
带有 mock 的HttpContextBase
它会在其 Request
中返回您的 URL .
路由在内部使用请求的 AppRelativeCurrentExecutionFilePath
匹配。 .
但是,此功能未公开,因此您需要传递 HttpContextBase
.
您需要创建一个 HttpContextBase
返回 HttpRequestBase
的类请求属性中的实例。HttpRequestBase
类需要返回你的路径,以 ~/
开头,在其AppRelativeCurrentExecutionFilePath
属性(property)。
您不需要实现任何其他属性,除非它们被 IRouteConstraint
使用。 s。
有人已经写过这个:Creating a RouteData instance from a URL
关于asp.net-mvc - ASP.NET MVC 从 URL 获取路由值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4993990/