定义一个类,写一个扩展方法,需要引入 Microsoft.AspNetCore.Http.Abstractions包 - public static class HttpRequestExtensions
- {
- public static string GetAbsoluteUri(this HttpRequest request)
- {
- return new StringBuilder()
- .Append(request.Scheme)
- .Append("://")
- .Append(request.Host)
- .Append(request.PathBase)
- .Append(request.Path)
- .Append(request.QueryString)
- .ToString();
- }
- }
复制代码
使用: - var url = HttpRequestExtensions.GetAbsoluteUri(Request);
复制代码
来源:https://blog.csdn.net/xingkongtianyuzhao/article/details/102642050 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |