开发者

ASP.NET MVC Get Route values from a URL

开发者 https://www.devze.com 2023-02-11 12:00 出处:网络
I want to work out what the route 开发者_如何学Pythonvalues for the UrlReferrer in the controller action would be.

I want to work out what the route 开发者_如何学Pythonvalues for the UrlReferrer in the controller action would be.

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.


You need call RouteTable.Routes.GetRouteData with a mocked HttpContextBase which returns your URL in its Request.

The routes are matched internally using the request's AppRelativeCurrentExecutionFilePath.
However, this functionality is not exposed, so you need to pass an 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.

You don't need to implement any other properties, unless they're used by IRouteConstraints.

Someone already wrote this: Creating a RouteData instance from a URL

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号