简体   繁体   English

获取Azure中资源的绝对URL

[英]Get the absolute URL of a resource in Azure

I'm a little perplexed. 我有点困惑。

How can I programmatically get the absolute URI to a resource in a Windows Azure Web application? 如何以编程方式获取Windows Azure Web应用程序中资源的绝对URI? I know the relative address, but in my specific case I need to provide a public one. 我知道相对地址,但是在我的具体情况下,我需要提供一个公开地址。

For the moment, this is what I've got: 目前,这是我所拥有的:

new Uri(new Uri(System.Web.HttpContext.Current.Request.Url.AbsoluteUri.Replace(System.Web.HttpContext.Current.Request.Url.PathAndQuery, "")), TrackRelativePath).AbsoluteUri

where TrackLocalPath is the relative path to a resource. 其中TrackLocalPath是资源的相对路径。

This works as long as the private port for the endpoint is the same as the public one (in this case it's port 80), however, if the ports are different, then that line points private port, which makes it useless outside the scope of the application. 只要端点的专用端口与公用端口相同(在本例中为端口80),此方法就起作用,但是,如果端口不同,则该行指向专用端口,这使得它在范围之外无效。应用程序。

Is there a way to programmatically get an absolute URL of a resource inside an Azure application? 有没有办法以编程方式获取Azure应用程序内部资源的绝对URL?

I'm sure I'm missing something fundamental here... (perhaps I've had too little sleep? >.< ) but I just can't put my finger on it. 我确定我在这里错过了一些基本知识……(也许我睡得太少了吗?>。<),但我只是不能将手指放在上面。

Can you use the HTTP_HOST header? 可以使用HTTP_HOST标头吗? That passes through unmodified and should include the external port. 这将通过未修改的,并且应包括外部端口。 Otherwise, you need to fix it up yourself. 否则,您需要自行修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM