I want to work out what the route values for the UrlReferrer
in the controller action would be.
我想弄清楚控制器操作中UrlReferrer的路由值是什么。
I can't figure out at what part in the MVC pipeline the incoming URL is converted into RouteValues, what I'm trying to achieve is close to that.
我无法弄清楚MVC管道中的哪个部分将传入的URL转换为RouteValues,我想要实现的是接近于此。
1 个解决方案
#1
6
You need call RouteTable.Routes.GetRouteData
with a mocked HttpContextBase
which returns your URL in its Request
.
您需要使用模拟的HttpContextBase调用RouteTable.Routes.GetRouteData,该HttpContextBase在其Request中返回您的URL。
The routes are matched internally using the request's AppRelativeCurrentExecutionFilePath
.
However, this functionality is not exposed, so you need to pass an HttpContextBase
.
使用请求的AppRelativeCurrentExecutionFilePath在内部匹配路由。但是,此功能未公开,因此您需要传递HttpContextBase。
You need to create an HttpContextBase
class which returns an HttpRequestBase
instance in its request property.
The HttpRequestBase
class needs to return your path, beginning with ~/
, in its AppRelativeCurrentExecutionFilePath
property.
您需要创建一个HttpContextBase类,该类在其请求属性中返回一个HttpRequestBase实例。 HttpRequestBase类需要在其AppRelativeCurrentExecutionFilePath属性中以〜/开头返回路径。
You don't need to implement any other properties, unless they're used by IRouteConstraint
s.
您不需要实现任何其他属性,除非它们被IRouteConstraints使用。
Someone already wrote this: Creating a RouteData instance from a URL
有人已写过:从URL创建RouteData实例
#1
6
You need call RouteTable.Routes.GetRouteData
with a mocked HttpContextBase
which returns your URL in its Request
.
您需要使用模拟的HttpContextBase调用RouteTable.Routes.GetRouteData,该HttpContextBase在其Request中返回您的URL。
The routes are matched internally using the request's AppRelativeCurrentExecutionFilePath
.
However, this functionality is not exposed, so you need to pass an HttpContextBase
.
使用请求的AppRelativeCurrentExecutionFilePath在内部匹配路由。但是,此功能未公开,因此您需要传递HttpContextBase。
You need to create an HttpContextBase
class which returns an HttpRequestBase
instance in its request property.
The HttpRequestBase
class needs to return your path, beginning with ~/
, in its AppRelativeCurrentExecutionFilePath
property.
您需要创建一个HttpContextBase类,该类在其请求属性中返回一个HttpRequestBase实例。 HttpRequestBase类需要在其AppRelativeCurrentExecutionFilePath属性中以〜/开头返回路径。
You don't need to implement any other properties, unless they're used by IRouteConstraint
s.
您不需要实现任何其他属性,除非它们被IRouteConstraints使用。
Someone already wrote this: Creating a RouteData instance from a URL
有人已写过:从URL创建RouteData实例