The HttpRequest class in Asp.Net 5 (vNext) contains (amongst other things) parsed details about the URL for the request, such as Scheme, Host
The other solutions did not fit well my needs because I wanted directly an URI object and I think it is better to avoid string concatenation (also) in this case so I created this extension methods than use a UriBuilder and works also with urls like http://localhost:2050:
public static Uri GetUri(this HttpRequest request)
{
var uriBuilder = new UriBuilder
{
Scheme = request.Scheme,
Host = request.Host.Host,
Port = request.Host.Port.GetValueOrDefault(80),
Path = request.Path.ToString(),
Query = request.QueryString.ToString()
};
return uriBuilder.Uri;
}