Append values to query string

后端 未结 8 1481
借酒劲吻你
借酒劲吻你 2020-11-28 20:32

I have set of URL\'s similar to the ones below in a list

  • http://somesite.com/backup/lol.php?id=1&server=4&location=us
  • http://somesite.com/news
8条回答
  •  鱼传尺愫
    2020-11-28 20:47

    The following solution works for ASP.NET 5 (vNext) and it uses QueryHelpers class to build a URI with parameters.

        public Uri GetUri()
        {
            var location = _config.Get("http://iberia.com");
            Dictionary values = GetDictionaryParameters();
    
            var uri = Microsoft.AspNetCore.WebUtilities.QueryHelpers.AddQueryString(location, values);
            return new Uri(uri);
        }
    
        private Dictionary GetDictionaryParameters()
        {
            Dictionary values = new Dictionary
            {
                { "param1", "value1" },
                { "param2", "value2"},
                { "param3", "value3"}
            };
            return values;
        }
    

    The result URI would have http://iberia.com?param1=value1¶m2=value2¶m3=value3

提交回复
热议问题