private static bool TryProcessPrefixTemplate(HttpRequest request, RoutePattern routePattern, out string path) { // TODO: Do you have a better way to process the prefix template? Contract.Assert(request != null); Contract.Assert(routePattern != null); HttpContext httpContext = request.HttpContext; TemplateBinderFactory factory = request.HttpContext.RequestServices.GetRequiredService <TemplateBinderFactory>(); TemplateBinder templateBinder = factory.Create(routePattern); RouteValueDictionary ambientValues = GetAmbientValues(httpContext); var templateValuesResult = templateBinder.GetValues(ambientValues, request.RouteValues); if (templateValuesResult == null) { // We're missing one of the required values for this route. path = default; return(false); } if (!templateBinder.TryProcessConstraints(httpContext, templateValuesResult.CombinedValues, out var _, out var _)) { path = default; return(false); } path = templateBinder.BindValues(templateValuesResult.AcceptedValues); int index = path.IndexOf("?", StringComparison.Ordinal); // remove the query string if (index >= 0) { path = path.Substring(0, index); } return(true); }