Get Host and Port Info using C#

Published on Tuesday, September 28, 2010

Here a good sample from Author: Steve Lautenschlager

Input: http://localhost:96/Cambia3/Temp/Test.aspx?q=item#fragment

Some HttpRequest path and URL properties:
Request.ApplicationPath:    /Cambia3
Request.CurrentExecutionFilePath:    /Cambia3/Temp/Test.aspx
Request.FilePath:    /Cambia3/Temp/Test.aspx
Request.Path:    /Cambia3/Temp/Test.aspx
Request.PathInfo:    
Request.PhysicalApplicationPath:    D:\Inetpub\wwwroot\CambiaWeb\Cambia3\
Request.QueryString:    /Cambia3/Temp/Test.aspx?query=arg
Request.Url.AbsolutePath:    /Cambia3/Temp/Test.aspx
Request.Url.AbsoluteUri:    http://localhost:96/Cambia3/Temp/Test.aspx?query=arg
Request.Url.Fragment:    
Request.Url.Host:    localhost
Request.Url.Authority:    localhost:96
Request.Url.LocalPath:    /Cambia3/Temp/Test.aspx
Request.Url.PathAndQuery:    /Cambia3/Temp/Test.aspx?query=arg
Request.Url.Port:    96
Request.Url.Query:    ?query=arg
Request.Url.Scheme:    http
Request.Url.Segments:    /Cambia3/Temp/Test.aspx