How to reliably build a URL in C# using the parts?
<p>I keep feeling like I'm reinventing the wheel, so I thought I'd ask the crowd here.  Imagine I have a code snippet like this:</p>

<pre><code>string protocol = "http"; // Pretend this value is retrieved from a config file
string host = "www.google.com"; // Pretend this value is retrieved from a config file
string path = "plans/worlddomination.html"; // Pretend this value is retrieved from a config file
</code></pre>

<p>I want to build the url "http://www.google.com/plans/worlddomination.html".  I keep doing this by writing cheesy code like this:</p>

<pre><code>protocol = protocol.EndsWith("://") ? protocol : protocol + "://";
path = path.StartsWith("/") ? path : "/" + path;    
string fullUrl = string.Format("{0}{1}{2}", protocol, host, path);
</code></pre>

<p>What I really want is some sort of API like:</p>

<pre><code>UrlBuilder builder = new UrlBuilder();
builder.Protocol = protocol;
builder.Host = host;
builder.Path = path;
builder.QueryString = null;
string fullUrl = builder.ToString();
</code></pre>

<p>I gotta believe this exists in the .NET framework somewhere, but nowhere I've come across.</p>

<p>What's the best way to build foolproof (i.e. never malformed) urls?</p>

<p>Thanks!</p>

<p>-Mike</p>
