6

I want to work out what the route values 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.

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.