.NET – Get protocol, host, and port

Even though @Rick has the accepted answer for this question, there’s actually a shorter way to do this, using the poorly named Uri.GetLeftPart() method. Uri url = new Uri(“http://www.mywebsite.com:80/pages/page1.aspx”); string output = url.GetLeftPart(UriPartial.Authority); There is one catch to GetLeftPart(), however. If the port is the default port for the scheme, it will strip it out. … Read more