I need to get RoutData by given URL string in ASP.NET MVC application.
I’ve found the way that I need to mock HttpContextBase based on my URL string and then pass it to RouteTable.Routes.GetRouteData() method in Route Parsing (Uri to Route) thread.
How to mock HttpContextBase to retrieve RouteData by URL string using RouteTable.Routes.GetRouteData()?
Or is there another way to retrieve RouteData by URL?
I used Moq to determine what members of
HttpContextBaseare used inGetRouteData(). They are:Request.AppRelativeCurrentExecutionFilePathshould return path with~, what I exactly need, so utility class may be like this one:Then, you can use it like this (for example on
~/Error/NotFound):Which should return an object that looks like this: