public override IHttpRouteData GetRouteData(string virtualPathRoot, HttpRequestMessage request) { // Optimize matching by comparing the static left part of the route url with the requested path. var requestedPath = GetCachedValue(request, RequestedPathKey, () => request.RequestUri.AbsolutePath.Substring(1)); if (!_visitor.IsStaticLeftPartOfUrlMatched(requestedPath)) { return(null); } // Let the underlying route match, and if it does, then add a few more constraints. var routeData = base.GetRouteData(virtualPathRoot, request); if (routeData == null) { return(null); } // Constrain by querystring param if there are any. var routeValues = new HttpRouteValueDictionary(routeData.Values); if (!_visitor.ProcessQueryStringConstraints((constraint, parameterName) => ProcessConstraint(request, constraint, parameterName, routeValues, HttpRouteDirection.UriResolution))) { return(null); } // Constrain by subdomain if configured var requestedSubdomain = GetCachedValue(request, RequestedSubdomainKey, () => _configuration.SubdomainParser(request.SafeGet(r => r.Headers.Host))); if (!_visitor.IsSubdomainMatched(requestedSubdomain)) { return(null); } // Constrain by culture name if configured var currentUICultureName = GetCachedValue(request, CurrentUICultureNameKey, () => _configuration.CurrentUICultureResolver(request, routeData)); if (!_visitor.IsCultureNameMatched(currentUICultureName)) { return(null); } return(routeData); }
public override RouteData GetRouteData(HttpContextBase httpContext) { // Optimize matching by comparing the static left part of the route url with the requested path. var requestedPath = GetCachedValue(httpContext, RequestedPathKey, () => httpContext.Request.AppRelativeCurrentExecutionFilePath.Substring(2) + httpContext.Request.PathInfo); if (!_visitor.IsStaticLeftPartOfUrlMatched(requestedPath)) { return(null); } // Let the underlying route match, and if it does, then add a few more constraints. var routeData = base.GetRouteData(httpContext); if (routeData == null) { return(null); } // Constrain by querystring param if there are any. if (!_visitor.ProcessQueryStringConstraints((constraint, parameterName) => ProcessConstraint(httpContext, constraint, parameterName, routeData.Values, RouteDirection.IncomingRequest))) { return(null); } // Constrain by subdomain if configured. var requestedSubdomain = GetCachedValue(httpContext, RequestedSubdomainKey, () => _configuration.SubdomainParser(httpContext.SafeGet(c => c.Request.Headers["host"]))); if (!_visitor.IsSubdomainMatched(requestedSubdomain)) { return(null); } // Constrain by culture name if configured. var currentUICultureName = GetCachedValue(httpContext, CurrentUICultureNameKey, () => _configuration.CurrentUICultureResolver(httpContext, routeData)); if (!_visitor.IsCultureNameMatched(currentUICultureName)) { return(null); } return(routeData); }