예제 #1
0
        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);
        }