예제 #1
0
        public static Uri SetParameter(this Uri url, string paramName, string value)
        {
            var queryParts = HttpUtility.ParseQueryString(url.Query);

            queryParts[paramName] = value;
            return(new Uri(url.AbsoluteUriExcludingQuery() + '?' + queryParts.ToString()));
        }
예제 #2
0
        public static Uri SetParameterIfDoesntExists(this Uri url, string paramName, string value)
        {
            if (url == null)
            {
                return(new Uri(string.Empty));
            }
            var queryParts = HttpUtility.ParseQueryString(url.Query);

            if (string.IsNullOrEmpty(value))
            {
                queryParts.Remove(paramName);
            }
            else if (queryParts[paramName] == null)
            {
                queryParts[paramName] = value;
            }
            return(new Uri(url.AbsoluteUriExcludingQuery() + '?' + queryParts));
        }