コード例 #1
0
ファイル: OverloadActionConstraint.cs プロジェクト: zt97/Mvc
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        // 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));
        }
コード例 #5
0
        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;
        }