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
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With