Answers:
您必须分别获取主机和路径。
 @Context.Request.Host@Context.Request.Path
@两个字符串之间是什么?你能解释一下吗?
                    @HttpContext而不是@Context。对于局部视图的@Context作品。我忘了使用吗?
                    Url.Action("Action", null, null, Request.Url.Scheme);  stackoverflow.com/questions/434604/...
                    您需要方案,主机,路径和queryString
@string.Format("{0}://{1}{2}{3}", Context.Request.Scheme, Context.Request.Host, Context.Request.Path, Context.Request.QueryString)
或使用新的C#6功能“字符串插值”
@($"{Context.Request.Scheme}://{Context.Request.Host}{Context.Request.Path}{Context.Request.QueryString}")
您可以使用扩展方法Request:
Request.GetDisplayUrl()
@using Microsoft.AspNetCore.Http.Extensions则可以使用@Context.Request.GetDisplayUrl()
                    Suitable only for display. This format should not be used in HTTP headers or other HTTP operations.基于此,我认为@tmg的解决方案是最好的(也许包装在您自己的扩展方法中)。
                    显然,在.net core 1.0 with中Microsoft.AspNetCore.Http.Extensions,这总是可能的,它添加了扩展名HttpRequest以获取完整的URL。GetEncodedUrl。
例如,从剃刀角度来看:
@using Microsoft.AspNetCore.Http.Extensions
...
<a href="@Context.Request.GetEncodedUrl()">Link to myself</a>
从2.0开始,还具有相对路径并查询GetEncodedPathAndQuery。
使用Uri 的AbsoluteUri属性和.Net核心,您必须像这样从请求中构建Uri,
 var location = new Uri($"{Request.Scheme}://{Request.Host}{Request.Path}{Request.QueryString}");
 var url = location.AbsoluteUri;
例如,如果请求网址为“ http://www.contoso.com/catalog/shownew.htm?date=today ”,则它将返回相同的网址。
您可以考虑使用此扩展方法(来自Microsoft.AspNetCore.Http.Extensions名称空间:
@Context.Request.GetDisplayUrl()
对于我的某些项目,我更喜欢更灵活的解决方案。有两种扩展方法。
1)第一种方法根据Uri传入的请求数据创建对象(具有一些可选参数的变体)。2)第二种方法接收Uri对象并string以以下格式返回(不带斜杠):Scheme_Host_Port
public static Uri GetUri(this HttpRequest request, bool addPath = true, bool addQuery = true)
    {
        var uriBuilder = new UriBuilder
        {
            Scheme = request.Scheme,
            Host = request.Host.Host,
            Port = request.Host.Port.GetValueOrDefault(80),
            Path = addPath ? request.Path.ToString() : default(string),
            Query = addQuery ? request.QueryString.ToString() : default(string)
        };
        return uriBuilder.Uri;
    }
    public static string HostWithNoSlash(this Uri uri)
    {
        return uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.UriEscaped);
    }
用法:
//before >> https://localhost:44304/information/about?param1=a¶m2=b
        Request.GetUri(addQuery: false);
        //after >> https://localhost:44304/information/about
        //before >> https://localhost:44304/information/about?param1=a¶m2=b
        new Uri("https://localhost:44304/information/about?param1=a¶m2=b").GetHostWithNoSlash();
        //after >> https://localhost:44304
public string BuildAbsolute(PathString path, QueryString query = default(QueryString), FragmentString fragment = default(FragmentString))
{
    var rq = httpContext.Request;
    return Microsoft.AspNetCore.Http.Extensions.UriHelper.BuildAbsolute(rq.Scheme, rq.Host, rq.PathBase, path, query, fragment);
}
httpContext哪里?那是行不通的  Microsoft.AspNetCore.Http.HttpContext.Request
                    如果您还希望从请求中获取端口号,则需要通过Request.HostAspNet Core 的属性访问它。
该Request.Host属性不仅仅是一个字符串,而是一个既包含主机域又包含端口号的对象。如果端口号是在URL中明确写出的(例如"https://example.com:8080/path/to/resource"),则调用Request.Host将为您提供主机域和端口号,如下所示:"example.com:8080"。
如果您只想要主机域的值或只想要端口号的值,则可以单独访问这些属性(即Request.Host.Host或Request.Host.Port)。
有一种干净的方法可以从Razor页面或PageModel类获取当前URL。那是:
Url.PageLink()
请注意,我的意思是“ ASP.NET Core Razor页面”,而不是MVC。
当我想在ASP.NET Core剃刀页面中打印规范的URL元标记时,我使用此方法。但是有一个问题!它将为您提供该页面的正确URL。让我解释。
说,根据您为页面定义的路由,您的网址应类似于
假设您已经为页面定义了路由“ Id”。因此,Url.PageLink()将为您提供确切的URL。如果用户在该URL上添加了其他内容,请说,
这样,您将无法从该方法获得“ somethingElse”。这就是为什么它非常适合在HTML页面中打印规范的URL元标记。