Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL string generation in .NET

Tags:

c#

.net

I was wondering if .NET had any class used to ease URL generation, similar to Path.Combine but for URLs.

Example of functionality I'm looking for:

string url = ClassName.Combine("http://www.google.com", "index")
            .AddQueryParam("search", "hello world").AddQueryParam("pagenum", 3);
// Result: http://www.google.com/index?search=hello%20world&pagenum=3
like image 528
Thomas Bonini Avatar asked Nov 10 '12 15:11

Thomas Bonini


2 Answers

I believe you are looking for the UriBuilder class.

Provides a custom constructor for uniform resource identifiers (URIs) and modifies URIs for the Uri class.

like image 113
Oded Avatar answered Oct 09 '22 17:10

Oded


Here's a similar question which links to two third party libraries:

C# Url Builder Class

As far as I know, there isn't anything "out-of-the-box" in .NET that allows one a fluent interface to construct the Url and QueryString.

like image 37
Alex Avatar answered Oct 09 '22 16:10

Alex