Is there a way that an ASP.NET application can display its URLs and hostname, knowing its own routes in the context of a request passing through a reverse proxy?
When requesting this URL through the gateway:
http://conoso.com/behind/some/reverseproxy/api/values/
The request is redirected by the gateway to another location:
http:
It accesses the following Get ValuesController Get ApiController method using the DefaultApi route:
public HttpResponseMessage Get()
{
var res = Request.CreateResponse();
res.Headers.Add(
"Location",
Url.Link(
"DefaultApi",
new
{
id = 1
}));
return res;
}
It returns the following header value:
Location: http://10.0.0.0/api/values/1
while I was hoping to send the correct path:
Location: http:
An alternative to using inline methods in a structure is to manually format the string:
var baseUrl = "http://conoso.com/behind/some/reverseproxy";
string.Format("{0}/values/1", baseUrl);
But this eliminates the evil code. Is there a cleaner approach?