比如 https://q.cnblogs.com/list/unsolved?page=3
这个url,在传统 asp.net 中 Request.RawUrl 的值是 /list/unsolved?page=3
,请问在 asp.net core 中如何获取这样的 url ?
今天在修复一个bug时发现了解决方法:
var rawUrl = Request.GetEncodedUrl();
GetEncodedUrl的实现源码在 Microsoft.AspNetCore.Http.Extensions/UriHelper.cs
未看到你说的这个属性,以下是扩展参考~
public static Uri GetUri(this HttpRequest request)
{
if (request == null)
throw new ArgumentNullException("request");
if (string.IsNullOrWhiteSpace(request.Scheme))
throw new ArgumentException("Http request Scheme is not specified");
if (!request.Host.HasValue)
throw new ArgumentException("Http request Host is not specified");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(request.Scheme).Append("://").Append((object) request.Host);
if (request.Path.HasValue)
stringBuilder.Append(request.Path.Value);
if (request.QueryString.HasValue)
stringBuilder.Append((object) request.QueryString);
return new Uri(stringBuilder.ToString());
}