请问 ASP.NET Core 中 Request.GetAbsoluteUri()
与 Request.GetDisplayUrl()
的区别是什么?
刚发现 Request.GetAbsoluteUri()
是我们自己实现的扩展方法
AbsoluteUri 应该是:完整路径且转译过的完整地址
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();
}