Learning ASP. NET MVC5 framework secrets notes-ASP. NET routing (5), mvc5-asp.net
3 VirtualPathDath
After introducing the returned type of the GetRouteData method, we will introduce the returned type of the RouteBase GetVirtualPath method VirtualPathData. When the RouteBase GetVirtualPath method is executed, if the variables defined in the routing template match the specified Variable list, it replaces the placeholder corresponding to the routing template with the value of the specified route variable and generates a virtual path. The generated virtual path and Route object are eventually encapsulated into a VirtualPathData object as the return value. They correspond to the VirtualPath and Route attributes of the returned VirtualPathData object. The DataTokens attribute of VirtualPathData and RouteData attributes of the same name are derived from the set of custom variables attached to the Route object.
public class VirtualPathData{public VirtualPathData(RouteBase route, string virtualPath);public RouteValueDictionary DataTokens { get; }public RouteBase Route { set; get; }public string VirtualPath { set; get; }}
The GetVirtualPath method of RouteBase has a parameter of the RequestContext type. A RequestContext object indicates the context of a request. It is not difficult to see from the following code snippets that it is actually an encapsulation of HTTP context and RouteData.
public class RequestContext{public RequestContext(HttpContextBase httpContext,RouteData routeData);public RequestContext();public virtual HttpContextBase HttpContext { set; get; }public virtual RouteData RouteData { set; get; }}