title: Is there a way to assign an external URL to a HyperLink without appending http:// or https:// (ie, the protocol)?
body: <p>I have a HyperLink defined like so:</p>
  
  <pre><code>&lt;asp:HyperLink ID="hltest" runat="server"&gt;&lt;/asp:HyperLink&gt;
  </code></pre>
  
  <p>In my code, I do this:</p>
  
  <pre><code>hltest.NavigateUrl = "www.google.com"
  </code></pre>
  
  <p>However, the actual link looks like this:</p>
  
  <pre><code>http://localhost:53305/www.google.com
  </code></pre>
  
  <p>I can append <code>http://</code> to the URL, but this not the preferred method because this URL is maintainable by the user.  If the user saves the URL as <code>http://www.google.com</code> then the URL will end up looking like <code>http://http://www.google.com</code>.  I know that I can strip <code>http://</code> from the URL and then add it back to ensure that it doesn't show up twice, but this is extra code/helper method that I would like to avoid writing.</p>
  
  <p>Edit:  This is the type of code I am trying to avoid having to write:</p>
  
  <pre><code>hltest.NavigateUrl = "http://" &amp; "hTTp://www.google.com".ToLower().Replace("http://", String.Empty)
  </code></pre>
  
  <p><strong>Update</strong>  I know I specifically asked how to do this without appending the protocol to the URL, but it looks like there's just no other way to do it.  The selected answer brought me to this solution:</p>
  
  <pre><code>Function GetExternalUrl(Url As String) As String
  
      Return If(New Uri(Url, UriKind.RelativeOrAbsolute).IsAbsoluteUri, Url, "http://" &amp; Url)
  
  End Function
  </code></pre>
  
  <p>This is great because, if the user enters just <code>www.google.com</code>, it will append <code>http://</code> to the URL.  If the user provides the protocol (http, https, ftp, etc), it will preserve it.</p>