从 Microsoft.AspNetCore.Http.HttpRequest 获取原始 URL [英] Get raw URL from Microsoft.AspNetCore.Http.HttpRequest

查看:27
本文介绍了从 Microsoft.AspNetCore.Http.HttpRequest 获取原始 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Asp.Net 5 (vNext) 中的 HttpRequest 类包含(除其他外)有关请求 URL 的解析详细信息,例如 Scheme主机Path

The HttpRequest class in Asp.Net 5 (vNext) contains (amongst other things) parsed details about the URL for the request, such as Scheme, Host, Path etc.

我还没有发现任何暴露原始请求 URL 的地方 - 只有这些解析值.(在之前的版本中有 Request.Uri)

I've haven't spotted anywhere yet that exposes the original request URL though - only these parsed values. (In previous versions there was Request.Uri)

我能否在不必将 HttpRequest 上可用的组件拼凑起来的情况下取回原始 URL?

Can I get the raw URL back without having to piece it together from the components available on HttpRequest?

推荐答案

貌似不能直接访问,但是可以使用框架构建:

It looks like you can't access it directly, but you can build it using the framework:

Microsoft.AspNetCore.Http.Extensions.UriHelper.GetFullUrl(Request)

你也可以使用上面的作为扩展方法.

You can also use the above as an extension method.

这将返回一个 string 而不是 Uri,但它应该可以达到目的!(这似乎也起到了 UriBuilder 的作用.)

This returns a string rather than a Uri, but it should serve the purpose! (This also seems to serve the role of the UriBuilder, too.)

感谢@mswietlicki 指出它只是被重构而不是丢失!还有@C-F 在我的回答中指出命名空间的变化!

Thanks to @mswietlicki for pointing out that it's just been refactored rather than missing! And also to @C-F to point out the namespace change in my answer!

这篇关于从 Microsoft.AspNetCore.Http.HttpRequest 获取原始 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆