从Microsoft.AspNetCore.Http.HttpRequest获取原始URL [英] Get raw URL from Microsoft.AspNetCore.Http.HttpRequest
问题描述
Asp.Net 5(vNext)中的 HttpRequest
类包含(除其他事项外)已解析的有关请求URL的详细信息,例如 Scheme
,主机
,路径
等
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拼凑起来就获取原始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屋!