首页 新闻 会员 周边 捐助

ASP.NET Core 中 Request.GetAbsoluteUri 与 Request.GetDisplayUrl 的区别

0
悬赏园豆:30 [已解决问题] 解决于 2019-11-05 13:51

请问 ASP.NET Core 中 Request.GetAbsoluteUri()Request.GetDisplayUrl() 的区别是什么?

问题补充:

刚发现 Request.GetAbsoluteUri() 是我们自己实现的扩展方法

dudu的主页 dudu | 高人七级 | 园豆:30948
提问于:2019-11-05 11:41
< >
分享
最佳答案
0
收获园豆:30
通信的搞程序 | 小虾三级 |园豆:1757 | 2019-11-05 13:34

UriHelper.cs 中的实现源码

// <summary>
/// Returns the combined components of the request URL in a fully un-escaped form (except for the QueryString)
/// suitable only for display. This format should not be used in HTTP headers or other HTTP operations.
/// </summary>
/// <param name="request">The request to assemble the uri pieces from.</param>
/// <returns>The combined components of the request URL in a fully un-escaped form (except for the QueryString)
/// suitable only for display.</returns>
public static string GetDisplayUrl(this HttpRequest request)
{
    var scheme = request.Scheme ?? string.Empty;
    var host = request.Host.Value ?? string.Empty;
    var pathBase = request.PathBase.Value ?? string.Empty;
    var path = request.Path.Value ?? string.Empty;
    var queryString = request.QueryString.Value ?? string.Empty;

    // PERF: Calculate string length to allocate correct buffer size for StringBuilder.
    var length = scheme.Length + SchemeDelimiter.Length + host.Length
        + pathBase.Length + path.Length + queryString.Length;

    return new StringBuilder(length)
        .Append(scheme)
        .Append(SchemeDelimiter)
        .Append(host)
        .Append(pathBase)
        .Append(path)
        .Append(queryString)
        .ToString();
}
dudu | 园豆:30948 (高人七级) | 2019-11-05 13:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册