private static ISet <string> GetCombinedKeys(RouteContext routeContext) { var keys = new HashSet <string>(routeContext.RouteData.Values.Keys, StringComparer.OrdinalIgnoreCase); keys.Remove("controller"); keys.Remove("action"); var queryString = routeContext.HttpContext.Request.QueryString.ToUriComponent(); if (queryString.Length > 0) { // We need to chop off the leading '?' var queryData = new FormDataCollection(queryString.Substring(1)); var queryNameValuePairs = queryData.GetJQueryNameValuePairs(); if (queryNameValuePairs != null) { foreach (var queryNameValuePair in queryNameValuePairs) { keys.Add(queryNameValuePair.Key); } } } return(keys); }
public static IEnumerable <KeyValuePair <string, string> > GetQueryNameValuePairs(this HttpRequestMessage request) { if (request == null) { throw Error.ArgumentNull("request"); } Uri uri = request.RequestUri; // Unit tests may not always provide a Uri in the request if (uri == null || String.IsNullOrEmpty(uri.Query)) { return(Enumerable.Empty <KeyValuePair <string, string> >()); } IEnumerable <KeyValuePair <string, string> > queryStringData; string cachedQueryString; request.Properties.TryGetValue <IEnumerable <KeyValuePair <string, string> > >(HttpPropertyKeys.RequestQueryNameValuePairsKey, out queryStringData); request.Properties.TryGetValue <string>(HttpPropertyKeys.CachedRequestQueryKey, out cachedQueryString); if (queryStringData == null || (cachedQueryString != null && !Object.ReferenceEquals(cachedQueryString, uri.Query ?? String.Empty))) { FormDataCollection formData = new FormDataCollection(uri); // The ToArray call here avoids reparsing the query string, and avoids storing an Enumerator state // machine in the request state. queryStringData = formData.GetJQueryNameValuePairs().ToArray(); request.Properties[HttpPropertyKeys.RequestQueryNameValuePairsKey] = queryStringData; request.Properties[HttpPropertyKeys.CachedRequestQueryKey] = uri.Query ?? String.Empty; } return(queryStringData); }
public static IEnumerable <KeyValuePair <string, string> > GetQueryNameValuePairs(this HttpRequestMessage request) { if (request == null) { throw Error.ArgumentNull("request"); } Uri uri = request.RequestUri; // Unit tests may not always provide a Uri in the request if (uri == null || String.IsNullOrEmpty(uri.Query)) { return(Enumerable.Empty <KeyValuePair <string, string> >()); } IEnumerable <KeyValuePair <string, string> > queryString; if (!request.Properties.TryGetValue <IEnumerable <KeyValuePair <string, string> > >(HttpPropertyKeys.RequestQueryNameValuePairsKey, out queryString)) { // Uri --> FormData --> NVC FormDataCollection formData = new FormDataCollection(uri); queryString = formData.GetJQueryNameValuePairs(); request.Properties.Add(HttpPropertyKeys.RequestQueryNameValuePairsKey, queryString); } return(queryString); }
// Create a IValueProvider for the given form, assuming a JQuery syntax. internal static IValueProvider GetJQueryValueProvider(this FormDataCollection formData) { if (formData == null) { throw Error.ArgumentNull("formData"); } IEnumerable <KeyValuePair <string, string> > nvc = formData.GetJQueryNameValuePairs(); return(new NameValuePairsValueProvider(nvc, CultureInfo.InvariantCulture)); }
private static ISet<string> GetCombinedKeys(RouteContext routeContext) { var keys = new HashSet<string>(routeContext.RouteData.Values.Keys, StringComparer.OrdinalIgnoreCase); keys.Remove("controller"); keys.Remove("action"); var queryString = routeContext.HttpContext.Request.QueryString.ToUriComponent(); if (queryString.Length > 0) { // We need to chop off the leading '?' var queryData = new FormDataCollection(queryString.Substring(1)); var queryNameValuePairs = queryData.GetJQueryNameValuePairs(); if (queryNameValuePairs != null) { foreach (var queryNameValuePair in queryNameValuePairs) { keys.Add(queryNameValuePair.Key); } } } return keys; }