I'm a little perplexed.
How can I programmatically get the absolute URI to a resource in a Windows Azure Web application? 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 Ur开发者_运维问答i(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.
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.
Is there a way to programmatically get an absolute URL of a resource inside an Azure application?
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? That passes through unmodified and should include the external port. Otherwise, you need to fix it up yourself.
精彩评论